Unsurly

Rewrites sur.ly links back to their original form

当前为 2016-08-12 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Unsurly
  3. // @namespace binoc.software.projects.userscript.unsurly
  4. // @description Rewrites sur.ly links back to their original form
  5. // @include http://forum.palemoon.org/*
  6. // @include https://forum.palemoon.org/*
  7. // @version 1.0a1
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. // Polyfill ES6 string.prototype.includes
  12. if (!String.prototype.includes) {
  13. String.prototype.includes = function(search, start) {
  14. 'use strict';
  15. if (typeof start !== 'number') {
  16. start = 0;
  17. }
  18. if (start + search.length > this.length) {
  19. return false;
  20. } else {
  21. return this.indexOf(search, start) !== -1;
  22. }
  23. };
  24. }
  25.  
  26. // Actual Script
  27. var links,thisLink;
  28. links = document.evaluate("//a[@href]",
  29. document,
  30. null,
  31. XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
  32. null);
  33. for (var i=0;i<links.snapshotLength;i++) {
  34. var thisLink = links.snapshotItem(i);
  35. if (thisLink.href.includes('sur.ly')) {
  36. thisLink.href = thisLink.href.replace('sur.ly/o/', '');
  37. thisLink.href = thisLink.href.replace('/AA010667', '');
  38. thisLink.href = unescape(thisLink.href);
  39. }
  40. }