Skip to content

Commit

Permalink
Latest anti-AMP patch and release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
csagan5 committed Dec 23, 2017
1 parent ba521c5 commit 7a436ca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
@@ -1,7 +1,11 @@
# 63.0.3239.105
# 63.0.3239.118
* limit impact of AMP-removal to not break tabs (https://github.com/bromite/bromite/issues/20)
* fix DuckDuckGo and StartPage suggestions (https://github.com/bromite/bromite/issues/19)
* revert /deep/ and ::shadow feature drop to attempt fixing DevTools support (https://github.com/bromite/bromite/issues/23)
* remove also ads from search results
* add Google search engine with English-only results, no RLZ and field trials
* updated adBlock filters
* fix build of x86 version (was broken in previous version)

# 63.0.3239.85
* no suggest URL for DuckDuckGo (https://github.com/bromite/bromite/issues/19)
Expand Down
2 changes: 1 addition & 1 deletion patches/privacy/disable-amp-from-search-results.patch
Expand Up @@ -62,6 +62,6 @@ new file mode 100644
+#ifndef dont_track_me_h
+#define dont_track_me_h
+
+#define DONT_TRACK_ME_JS "// Bromite click-tracking and AMP removal v0.3.1\nfunction recreateHyperlink(a) {\n // create new A element - old one has event listeners attached\n var newA = document.createElement('a');\n newA.referrerPolicy = 'origin';\n\n // remove AMP class, get actual page URL\n var ampCur = a.getAttribute('data-amp-cur');\n if (ampCur) {\n newA.href = ampCur;\n a.classList.remove('amp_r');\n } else {\n var realLink = getRealLinkFromGoogleUrl(a);\n if (realLink) {\n newA.href = realLink;\n } else {\n // might not be an actual hyperlink, ignore it\n if (!a.href) {\n return;\n }\n newA.href = a.href;\n }\n }\n // copy CSS classes\n newA.className = a.className;\n\n // copy nodes inside the hyperlink\n while (a.firstChild) {\n newA.appendChild(a.lastChild);\n }\n // replace hyperlink\n a.parentNode.replaceChild(newA, a);\n}\n\n/**\n * @returns {String} the real URL if the given link is a Google redirect URL.\n */\nfunction getRealLinkFromGoogleUrl(a) {\n if ((a.hostname === location.hostname || a.hostname === 'www.google.com') &&\n /^\\/(local_)?url$/.test(a.pathname)) {\n // Google Maps / Dito (/local_url?q=<url>)\n // Mobile (/url?q=<url>)\n var url = /[?&](?:q|url)=((?:https?|ftp)[%:][^&]+)/.exec(a.search);\n if (url) {\n return decodeURIComponent(url[1]);\n }\n // Help pages, e.g. safe browsing (/url?...&q=%2Fsupport%2Fanswer...)\n url = /[?&](?:q|url)=((?:%2[Ff]|\\/)[^&]+)/.exec(a.search);\n if (url) {\n return a.origin + decodeURIComponent(url[1]);\n }\n }\n}\n\nfunction sanitizeAllHyperlinks() {\n // find regular search results hyperlinks\n var h = document.getElementsByClassName('_Olt');\n for (var i = 0; i < h.length; i++) {\n var a = h[i];\n if (a.classList.contains('_bCp'))\n recreateHyperlink(a);\n }\n\n // re-create hyperlinks (regular, sub-results, wikipedia links and such)\n [document.getElementsByClassName('_G0q'), document.getElementsByClassName('_ust')].forEach(function(h) {\n for (var i = 0; i < h.length; i++) {\n recreateHyperlink(h[i]);\n }\n });\n}\n\nfunction sanitizeAds() {\n // scan all divs\n var div = document.getElementById('tads');\n if (div) {\n div.style.display = 'none';\n }\n}\n\n// avoid running cleanup on non-search pages\nif ((document.location.host.indexOf(\"images.google.\") == -1) && (document.location.host.indexOf(\"news.google.\") == -1)) {\n document.addEventListener(\"DOMContentLoaded\", function() { sanitizeAds(); sanitizeAllHyperlinks(); }, false);\n}\n"
+#define DONT_TRACK_ME_JS "// Bromite click-tracking and AMP removal v0.3.4\n\nfunction recreateHyperlink(a) {\n // create new A element - old one has event listeners attached\n var newA = document.createElement('a');\n newA.referrerPolicy = 'origin';\n // property set when hyperlink has been created by this script\n newA.sane = 1;\n\n // remove AMP class, get actual page URL\n var ampCur = a.getAttribute('data-amp-cur');\n if (ampCur) {\n newA.href = ampCur;\n a.classList.remove('amp_r');\n } else {\n var realLink = getRealLinkFromGoogleUrl(a);\n if (realLink) {\n newA.href = realLink;\n } else {\n // might not be an actual hyperlink, ignore it\n if (!a.href) {\n return false;\n }\n // leave original href unchanged\n newA.href = a.href;\n }\n }\n // copy CSS classes\n newA.className = a.className;\n\n // copy nodes inside the hyperlink\n while (a.firstChild) {\n newA.appendChild(a.lastChild);\n }\n // replace hyperlink\n a.parentNode.replaceChild(newA, a);\n return true;\n}\n\nfunction isResult(a) {\n var inlineMousedown = a.getAttribute('onmousedown');\n if (!inlineMousedown)\n\treturn false;\n // return rwt(....); // E.g Google search results.\n // return google.rwt(...); // E.g. sponsored search results\n // return google.arwt(this); // E.g. sponsored search results (dec 2016).\n return /\\ba?rwt\\(/.test(inlineMousedown) || /\\bctpacw\\b/.test(inlineMousedown);\n}\n\nfunction handlePointerPress(e) {\n var a = e.target;\n while (a && !a.href) {\n a = a.parentElement;\n }\n if (!a || a.sane) {\n return;\n }\n if (isResult(a)) {\n // In Chrome, removing onmousedown during event dispatch does not\n // prevent the inline listener from running... So we have to cancel\n // event propagation just in case.\n e.stopImmediatePropagation();\n\n a.removeAttribute('onmousedown');\n // remove also ping and oncontextmenu, just in case\n a.removeAttribute('ping');\n a.removeAttribute('oncontextmenu');\n // (event attributes are removed here, but hyperlinks is going to be re-created anyway)\n }\n recreateHyperlink(a);\n}\n\n/**\n * @returns {String} the real URL if the given link is a Google redirect URL.\n */\nfunction getRealLinkFromGoogleUrl(a) {\n if ((a.hostname === location.hostname || a.hostname.indexOf('www.google.') == 0) &&\n /^\\/(local_)?url$/.test(a.pathname)) {\n // Google Maps / Dito (/local_url?q=<url>)\n // Mobile (/url?q=<url>)\n var url = /[?&](?:q|url)=((?:https?|ftp)[%:][^&]+)/.exec(a.search);\n if (url) {\n return decodeURIComponent(url[1]);\n }\n // Help pages, e.g. safe browsing (/url?...&q=%2Fsupport%2Fanswer...)\n url = /[?&](?:q|url)=((?:%2[Ff]|\\/)[^&]+)/.exec(a.search);\n if (url) {\n return a.origin + decodeURIComponent(url[1]);\n }\n }\n}\n\nfunction sanitizeAds() {\n // scan all divs\n var div = document.getElementById('tads');\n if (div) {\n div.style.display = 'none';\n\treturn true;\n }\n return false;\n}\n\n/*\nfunction sanitizeAllHyperlinks() {\n var saned = 0;\n var h = document.getElementsByTagName('a');\n for (var i = 0; i < h.length; i++) {\n var a = h[i];\n if (a.sane) {\n // skip if this hyperlink is already sane\n continue;\n }\n\n var res = recreateHyperlink(a);\n if (res) saned++;\n }\n console.log(\"sanitized \", saned, \" hyperlinks\");\n\n return saned;\n}*/\n\n// avoid running cleanup on non-search pages\nif ((document.location.host.indexOf(\"images.google.\") == -1) && (document.location.host.indexOf(\"news.google.\") == -1)) {\n // sanitize hyperlinks as they are touched\n document.addEventListener('touchstart', handlePointerPress, true);\n document.addEventListener(\"DOMContentLoaded\", function(e) { sanitizeAds(); }, false);\n}\n"
+
+#endif // dont_track_me_h

0 comments on commit 7a436ca

Please sign in to comment.