DLE links decoder

Прямые ссылки на сайтах с движком DataLife Engine (DLE)

  1. // ==UserScript==
  2. // @name DLE links decoder
  3. // @namespace lainscripts_dle_links_decoder
  4. // @version 1.3
  5. // @description Прямые ссылки на сайтах с движком DataLife Engine (DLE)
  6. // @author lainverse
  7. // @match *://*/*
  8. // @grant none
  9. // ==/UserScript==
  10. // Script based on a similar script by raletag:
  11. // https://gf.qytechs.cn/en/scripts/22290-Прямые-ссылки-в-dle
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. var impCodes = '%3B%2C%2F%3F%3A%40%26%3D%2B%24%23',
  17. impRegex = new RegExp((impCodes.replace(/%/g,'|%').replace('|','')), 'gi'),
  18. impDecoded = decodeURIComponent(impCodes),
  19. impReplacer = function(ch) {
  20. return impDecoded[impCodes.indexOf(ch.toUpperCase())/3];
  21. };
  22. function decodeImportant(text) {
  23. return text.replace(impRegex, impReplacer);
  24. }
  25.  
  26. function linkHandler(e){
  27. var link = e.target, url = link.href, url64;
  28.  
  29. // Detach event from a link since we don't need to parse it more than once
  30. link.removeEventListener('mouseenter', linkHandler, false);
  31.  
  32. // Check if it's one of the DLE-redirected links and exit if not
  33. url64 = (url.match(/([?&]url=|\/leech_out\.php\?.:)([^&]+)(&|$)/i)||[])[2];
  34. if (!url64) {
  35. return true;
  36. }
  37.  
  38. // Try to decode base64 encoded link, if fails then take it as-is
  39. try {
  40. url64 = decodeURIComponent(url64);
  41. url = window.atob(url64);
  42. } catch(ignore) {
  43. url = url64;
  44. }
  45.  
  46. // Decode important %-encoded parts of a link (browser should handle the rest)
  47. url = decodeImportant(url);
  48.  
  49. // Replace target with decoded link and make it open in a new tab by default
  50. console.log('Replaced ' + link.href + ' with ' + url);
  51. link.href = url;
  52. link.target = '_blank';
  53.  
  54. return true;
  55. }
  56.  
  57. // Get a list of all link in a given object and attach mouseover event to it
  58. function attachEventToLinks(root) {
  59. var links = root.querySelectorAll('a[href]'),
  60. i = links.length;
  61. while(i--) {
  62. links[i].addEventListener('mouseenter', linkHandler, false);
  63. }
  64. }
  65.  
  66. // Parse all existing links
  67. attachEventToLinks(document);
  68.  
  69. // Monitor changes to the document structure and attach events to all new links
  70. var o = new MutationObserver(function(ms){
  71. ms.forEach(function(m){
  72. m.addedNodes.forEach(function(n){
  73. if (n.nodeType !== Node.ELEMENT_NODE) {
  74. return; // parse only document elements and skip the rest
  75. }
  76. if (n.href) {
  77. n.addEventListener('mouseenter', linkHandler, false);
  78. return; // if node is a link attach event and exit since we
  79. // don't want to parse link's content (links within links?!)
  80. }
  81. attachEventToLinks(n);
  82. });
  83. });
  84. });
  85. o.observe(document, {childList: true, subtree: true});
  86. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址