Ghost Trappers Wiki links on Feed

Changes the loot you find to be hyperlinks to the wiki

当前为 2017-08-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Ghost Trappers Wiki links on Feed
  3. // @version 0.6
  4. // @description Changes the loot you find to be hyperlinks to the wiki
  5. // @author Hazado
  6. // @match *www.ghost-trappers.com/fb/camp.php*
  7. // @match *www.ghost-trappers.com/fb/hunt.php*
  8. // @grant none
  9. // @namespace https://greasyfork.org/users/149039
  10. // ==/UserScript==
  11.  
  12. function getMatches(string, regex, index) {
  13. index || (index = 1); // default to the first capturing group
  14. var matches = [];
  15. var match;
  16. while (match = regex.exec(string)) {
  17. matches.push(match[index]);
  18. }
  19. return matches;
  20. }
  21.  
  22. String.prototype.capitalize = function() {
  23. return this.charAt(0).toUpperCase() + this.slice(1).toLowerCase();
  24. };
  25.  
  26. for (i = 0; i < document.querySelectorAll('b').length; i++) {
  27. if (document.querySelectorAll('b')[i].innerHTML.search('^<br>[0-9]+') === 0)
  28. {
  29. var matches = getMatches(document.querySelectorAll('b')[i].innerHTML,/<br>[0-9]+(?: x)? ([a-zA-Z -:()ß]*)/g,0);
  30. var saved = getMatches(document.querySelectorAll('b')[i].innerHTML,/(<br>[0-9]+(?: x)? )[a-zA-Z -:()ß]*/g,0);
  31. document.querySelectorAll('b')[i].innerHTML = null;
  32. for (j = 0; j < matches.length; j++) {
  33. var a = document.createElement('a');
  34. if (matches[j].replace(/_\(special\)/,'').match(/[A_Z]*\.[0-9]/) !== null) a.innerHTML = saved[j]+'<a href="http://wiki.ghost-trappers.com/index.php/'+matches[j].replace(/ /g,'_').replace(/_-_/,'_').replace(/-/,'/').replace(/Blueprint:_|_\(special\)|Molding_half:_|Schematic:_/,'')+'" target="_blank">'+matches[j]+'</a>';
  35. else a.innerHTML = saved[j]+'<a href="http://wiki.ghost-trappers.com/index.php/'+matches[j].replace(/ /g,'_').replace(/_-_/,'_').replace(/-/,'/').replace(/Blueprint:_|_\(special\)|Molding_half:_|Schematic:_/,'').capitalize()+'" target="_blank">'+matches[j]+'</a>';
  36. while(a.firstChild) {
  37. document.querySelectorAll('b')[i].appendChild(a.firstChild);
  38. }
  39. }
  40. }
  41. }