DLE links decoder

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

目前为 2016-08-28 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name DLE links decoder
  3. // @namespace lainscripts_dle_links_decoder
  4. // @version 0.8
  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://greasyfork.org/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 clickHandler(e){
  27. var link = e.target, url = link.href, url64;
  28. if (!url) {
  29. while (!url && link !== this) {
  30. link = link.parentNode;
  31. url = link.href;
  32. }
  33. if (!url) {
  34. return true;
  35. }
  36. }
  37. url64 = (url.match(/([?&]url=|\/leech_out\.php\?.:)([^&]+)(&|$)/i)||[])[2];
  38. if (!url64) {
  39. return true;
  40. }
  41.  
  42. try {
  43. url64 = decodeURIComponent(url64);
  44. url = window.atob(url64);
  45. } catch(ignore) {
  46. url = url64;
  47. }
  48.  
  49. url = decodeImportant(url);
  50. console.log('Replaced ' + link.href + ' with ' + url);
  51. link.href = url;
  52. link.target = '_blank';
  53.  
  54. return true;
  55. }
  56.  
  57. document.addEventListener('click', clickHandler, false);
  58. document.addEventListener('contextmenu', clickHandler, false);
  59. })();