cf.replace.user.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // ==UserScript==
  2. // @name Replace CloudFlare links
  3. // @description Take action against CloudFlare. Replace CloudFlare links.
  4. // @namespace deCloudflare_us_replace-cf
  5. // @author Matthew L. Tanner, CrimeFlare
  6. // @match https://*/*
  7. // @match http://*/*
  8. // @version 1.0.0.2
  9. // @grant none
  10. // @run-at document-end
  11. // @license MIT
  12. // ==/UserScript==
  13. // this script will not run on those sites
  14. // e.g. ['www.youtube.com','www.google.com']
  15. let DONT_RUN_FQDNS = ['web.archive.org'];
  16. //-----
  17. // [Documentation] https://notabug.org/dCF/deCloudflare/src/master/tool/userscripts/README.md
  18. // [About API] http://about-karmaapi.go.crimeflare.eu.org
  19. const api_url = 'https://karma.crimeflare.eu.org/api/is/cloudflare/';
  20. let fqdn_self = location.hostname;
  21. function scanme() {
  22. let fqdns = {};
  23. document.querySelectorAll('a[href]:not([xcf])').forEach(l => {
  24. try {
  25. let u = new URL(l.href);
  26. if (u.hostname != fqdn_self && (u.protocol == 'https:' || u.protocol == 'http:')) {
  27. l.setAttribute('xcf', 'q');
  28. let fqdn = u.hostname;
  29. if (!/^(|(.*)\.)archive\.org$/.test(fqdn)) {
  30. if (fqdns[fqdn] == undefined) {
  31. fqdns[fqdn] = [];
  32. }
  33. fqdns[fqdn].push(l);
  34. }
  35. }
  36. } catch (x) {}
  37. });
  38. let ff_str = Object.keys(fqdns).slice(0, 200).join(',');
  39. if (ff_str == '') {
  40. return;
  41. }
  42. try {
  43. fetch(api_url, {
  44. method: 'POST',
  45. mode: 'cors',
  46. body: 'ff=' + ff_str,
  47. referrer: '',
  48. headers: {
  49. 'Content-Type': 'application/x-www-form-urlencoded'
  50. }
  51. }).then(x => x.json()).then(x => {
  52. for (let xx in x) {
  53. if (fqdns[xx]) {
  54. if (x[xx]) {
  55. fqdns[xx].forEach(qs => {
  56. qs.setAttribute('xcf', 'y');
  57. qs.href = 'https://web.archive.org/web/' + qs.href;
  58. });
  59. } else {
  60. fqdns[xx].forEach(qs => {
  61. qs.setAttribute('xcf', 'n');
  62. });
  63. }
  64. }
  65. }
  66. }).catch(x => {});
  67. } catch (x) {}
  68. }
  69. if (!DONT_RUN_FQDNS.includes(fqdn_self) && !/\.crimeflare\.eu\.org$/.test(fqdn_self)) {
  70. try {
  71. const style = document.createElement('style');
  72. document.head.appendChild(style);
  73. const styleSheet = style.sheet;
  74. styleSheet.insertRule("a[xcf='y']{opacity:0.6;text-decoration-line:line-through !important;text-decoration-color:red !important;text-decoration-style:double !important;}", 0);
  75. } catch (x) {}
  76. scanme();
  77. (new MutationObserver(scanme)).observe(document, {
  78. attributes: true,
  79. attributeFilter: ['href'],
  80. childList: true,
  81. subtree: true
  82. });
  83. }