Skip to content

Commit

Permalink
AG-37564 Force to open google image links in new tab. #104
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 0c580b8
Author: jellizaveta <[email protected]>
Date:   Wed Nov 13 12:48:27 2024 +0300

    fix changelog

commit ffd002e
Merge: 73193e8 6f51dee
Author: jellizaveta <[email protected]>
Date:   Tue Nov 12 20:29:01 2024 +0300

    merge master, update changelog version

commit 73193e8
Author: jellizaveta <[email protected]>
Date:   Tue Nov 12 20:28:24 2024 +0300

    merge master, update changelog version

commit 03c1b2e
Merge: da9b356 ebc7b0c
Author: jellizaveta <[email protected]>
Date:   Tue Nov 12 20:27:16 2024 +0300

    Merge branch 'master' into fix/AG-37564

commit 6f51dee
Author: Slava Leleka <[email protected]>
Date:   Tue Nov 12 11:18:10 2024 +0300

    CHANGELOG.md edited online with Bitbucket

commit 7546aad
Author: Slava Leleka <[email protected]>
Date:   Tue Nov 12 11:18:04 2024 +0300

    CHANGELOG.md edited online with Bitbucket

commit da9b356
Author: jellizaveta <[email protected]>
Date:   Mon Nov 11 20:21:34 2024 +0300

    fix changelog, styles

commit c9f2db1
Author: jellizaveta <[email protected]>
Date:   Mon Nov 11 15:51:02 2024 +0300

    AG-37564 Force to open google image links in new tab. #104
  • Loading branch information
jellizaveta committed Nov 13, 2024
1 parent ebc7b0c commit 8c215c8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
19 changes: 14 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,22 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic
[Keep a Changelog]: https://keepachangelog.com/en/1.0.0/
[Semantic Versioning]: https://semver.org/spec/v2.0.0.html

## [1.0.53] - 2024-11-06
## [1.0.56] - 2024-11-13

### Fixed

- Force to open google image links in new tab [#104].

[1.0.56]: https://github.com/AdguardTeam/DisableAMP/compare/v1.0.54...v1.0.56
[#104]: https://github.com/AdguardTeam/DisableAMP/issues/104

## [1.0.54] - 2024-11-06

### Fixed

- Redirect on Turbo pages [#58].

[1.0.53]: https://github.com/AdguardTeam/Scriptlets/compare/v1.0.52...v1.0.53
[1.0.54]: https://github.com/AdguardTeam/DisableAMP/compare/v1.0.52...v1.0.54
[#58]: https://github.com/AdguardTeam/DisableAMP/issues/58

## [1.0.52] - 2024-10-28
Expand All @@ -26,7 +35,7 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic

- Infinite reloading on innogyan.in [#103].

[1.0.52]: https://github.com/AdguardTeam/Scriptlets/compare/v1.0.51...v1.0.52
[1.0.52]: https://github.com/AdguardTeam/DisableAMP/compare/v1.0.51...v1.0.52
[#103]: https://github.com/AdguardTeam/DisableAMP/issues/103

## [1.0.51] - 2024-10-24
Expand All @@ -39,7 +48,7 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic

- Link breakage due to deletion of amp string. [#102].

[1.0.51]: https://github.com/AdguardTeam/Scriptlets/compare/v1.0.49...v1.0.51
[1.0.51]: https://github.com/AdguardTeam/DisableAMP/compare/v1.0.49...v1.0.51
[#102]: https://github.com/AdguardTeam/DisableAMP/issues/102

## [1.0.49] - 2024-10-18
Expand All @@ -48,7 +57,7 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic

- Redirect to canonical website for `amppoject` pages [#98], [#96], [#100].

[1.0.49]: https://github.com/AdguardTeam/Scriptlets/compare/v1.0.47...v1.0.49
[1.0.49]: https://github.com/AdguardTeam/DisableAMP/compare/v1.0.47...v1.0.49
[#98]: https://github.com/AdguardTeam/DisableAMP/issues/98
[#96]: https://github.com/AdguardTeam/DisableAMP/issues/96
[#100]: https://github.com/AdguardTeam/DisableAMP/issues/100
26 changes: 23 additions & 3 deletions src/google-amp.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,35 @@ const AMP_ATTRIBUTES_TO_REMOVE = [
'data-amp-title',
'data-amp',
'data-amp-vgi',
'jsaction',
];
const AMP_IMAGE_LINK_SELECTOR = 'a[data-ved]:has(> div[class] > span + svg)';
const AMP_LINK_SELECTOR = 'a[data-amp]';

/**
* Prevent amp links from open in google iframe
* Prevent AMP links from Google News, Search, and Images from opening within Google's iframe
* e.g. google.com/amp/amp.website.com
*/
export const cleanAmpLink = () => {
const ampLinks = document.querySelectorAll('a[data-amp]');
ampLinks.forEach((link) => {
const ampImageLinks = document.querySelectorAll(AMP_IMAGE_LINK_SELECTOR);
const siblingAmpLinks = [];

ampImageLinks.forEach((link) => {
const siblingAmpLink = link.previousElementSibling;
if (!siblingAmpLink || !siblingAmpLink.hasAttribute('data-ved')) {
return;
}
siblingAmpLinks.push(siblingAmpLink);
});

const ampLinks = document.querySelectorAll(AMP_LINK_SELECTOR);
const allAmpLinks = [
...ampLinks,
...ampImageLinks,
...siblingAmpLinks,
];

allAmpLinks.forEach((link) => {
AMP_ATTRIBUTES_TO_REMOVE.forEach((attr) => {
link.removeAttribute(attr);
});
Expand Down

0 comments on commit 8c215c8

Please sign in to comment.