Skip to content

Commit

Permalink
Pull request: AG-9730 Adguard program for Android not blocked Turbo-p…
Browse files Browse the repository at this point in the history
…ages Yandex

Merge in EXTENSIONS/disable-amp from fix/AG-9730 to master

Squashed commit of the following:

commit 3264a9d
Author: tvinzz <[email protected]>
Date:   Tue Aug 31 12:14:59 2021 +0300

    fixed include pattern

commit b8b08ba
Author: tvinzz <[email protected]>
Date:   Tue Aug 31 02:17:25 2021 +0300

    fixed amp redirect
  • Loading branch information
tvinzz committed Aug 31, 2021
1 parent 38cc720 commit f6a8e49
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
3 changes: 3 additions & 0 deletions meta.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
// @include https://www.google.*/*
// @include https://yandex.*/*
// @include https://*.turbopages.org/*
// @include https://*/amp/*
// @include https://*/amp-*/*
// @include https://*/?amp
// @run-at document-end
// ==/UserScript==
11 changes: 4 additions & 7 deletions src/google-amp.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ const hideAmpIcon = (amp) => {
/**
* Redirects amp version to normal
*/
const ampRedirect = () => {
if (document.location.pathname.includes('/amp/')) {
const originalUrl = document.querySelector('#amp-hdr .amp-cantxt')?.textContent;
if (originalUrl && URL_PATTERN_REGEX.test(originalUrl)) {
document.location.replace(originalUrl);
}
export const ampRedirect = () => {
const canonicalLink = document.querySelector('head > link[rel="canonical"]');
if (canonicalLink && URL_PATTERN_REGEX.test(canonicalLink.href)) {
document.location.replace(canonicalLink.href);
}
};

Expand Down Expand Up @@ -86,7 +84,6 @@ const replaceCdnAmp = () => {
};

const preventAmp = () => {
ampRedirect();
replaceByAmpCurAttribute();
replaceCdnAmp();
};
Expand Down
11 changes: 5 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { redirectTurboPages } from './yandex-turbo';
import disableAmp from './google-amp';

import disableAmp, { ampRedirect } from './google-amp';

const observeDomChanges = (callback) => {
new MutationObserver(callback).observe(document, {
Expand All @@ -9,10 +8,10 @@ const observeDomChanges = (callback) => {
});
};

if (document.location.origin.includes('google.')) {
observeDomChanges(disableAmp);
}

if (document.location.href.includes('https://yandex.ru/turbo')) {
redirectTurboPages();
} else if (document.location.origin.includes('google.')) {
observeDomChanges(disableAmp);
} else {
observeDomChanges(ampRedirect);
}

0 comments on commit f6a8e49

Please sign in to comment.