-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgreasemonkey_hook_googlesearch.user.js
More file actions
97 lines (80 loc) · 2.69 KB
/
Copy pathgreasemonkey_hook_googlesearch.user.js
File metadata and controls
97 lines (80 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// ==UserScript==
// @name AMP Removal from Google Search Results
// @namespace http
// @description Attempts to remove AMP related attributes from Google search results so that you're not redirected to an AMP page in the first place
// @include *://*google*/search*
// @include *://news.google*/*
// @run-at document-end
// @grant none
// @downloadURL https://github.com/bentasker/RemoveAMP/raw/master/greasemonkey_hook_googlesearch.user.js
// @version 1.5
//
//
// See https://projects.bentasker.co.uk/jira_projects/browse/MISC-29.html#comment2512640
//
// Author: B Tasker
// ==/UserScript==
var AMPCheck = debounce(function() {
var da;
var bads = ['data-amp','data-amp-cur','data-amp-title','data-amp-vgi','ping'];
var eles = document.getElementsByClassName('amp_r');
for (var i=0; i<eles.length; i++){
if (eles[i].tagName.toLowerCase() != 'a'){
continue;
}
da = eles[i].getAttribute('data-amp-cur');
if (! da){
continue;
}
if (!da.includes('?')){
da += '?';
}
eles[i].href = da;
for (n=0; n<bads.length; n++){
eles[i].removeAttribute(bads[n]);
}
}
// FKAMP-5 Check for iframes pointed towards the ampproject CDN
var ifs = document.getElementsByTagName('iframe');
for (var i=0; i<ifs.length; i++){
// Check whether the iframe source is pointing towards the AMP cdn
s = ifs[i].getAttribute('src');
if (s && s.includes('.cdn.ampproject.org/')){
// Extract the source domain name and path from the amp cdn url
s=s.split("#")[0];
e=s.split("/");
proto = 'https';
if (e[4] != 's'){
proto = 'http';
}
// Start building a new URL
p=[proto+":",'',e[5]]
// start at position 6 for the path
for (var x=6; x<e.length; x++){
p.push(e[x])
}
newurl = p.join("/");
window.location.replace(newurl);
return;
}
}
}, 500);
/* Taken from https://davidwalsh.name/javascript-debounce-function */
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
};
window.addEventListener ("load", function(){
AMPCheck();
document.addEventListener("DOMNodeInserted", AMPCheck, false);
}, false);