[Konachan] Wiki: Tag Links

Adds "Edit Tag" and "Tag History" Links to the footer on the wiki pages. The links are also added to the artist creation page if there's a name in the url.

  1. // ==UserScript==
  2. // @name [Konachan] Wiki: Tag Links
  3. // @namespace Zolxys
  4. // @description Adds "Edit Tag" and "Tag History" Links to the footer on the wiki pages. The links are also added to the artist creation page if there's a name in the url.
  5. // @include /^https?://konachan\.com/(wiki/show|artist/create)\?/
  6. // @include /^https?://konachan\.net/(wiki/show|artist/create)\?/
  7. // @version 2.2
  8. // @grant none
  9. // ==/UserScript==
  10. var t = /[\?&](title|name)=([^&]+)(&|$)/.exec(location.search);
  11. if (t == null)
  12. return;
  13. t = t[2];
  14. var r = new XMLHttpRequest();
  15. r.onreadystatechange = function() {
  16. if (this.readyState == 4 && this.status == 200) {
  17. var v = JSON.parse(this.responseText);
  18. for (; v[0].name != decodeURIComponent(t); v.shift())
  19. if (v.length == 0)
  20. return;
  21. var o = document.getElementById('content').firstElementChild;
  22. while (o != null) {
  23. if (o.nodeName == 'DIV' && o.className == 'footer') {
  24. var l = o.firstElementChild
  25. if (l.nodeName == 'UL') {
  26. var ne = document.createElement('div');
  27. ne.className = 'footer';
  28. ne.style.clear = 'both';
  29. o.parentNode.insertBefore(ne,o);
  30. o = ne;
  31. ne.appendChild(document.createElement('br'));
  32. }
  33. else if (l.nodeName != 'A')
  34. return;
  35. var p, a = o.getElementsByTagName('A');
  36. if (a.length == 0)
  37. p = o.firstChild;
  38. else {
  39. p = a[a.length - 1];
  40. if (/^[^#]+\?([^#]+&)?version=\d+($|&)/.test(p.href))
  41. p = p.previousElementSibling;
  42. p = p.nextSibling;
  43. o.insertBefore(document.createTextNode(' | '),p);
  44. }
  45. ne = document.createElement('a');
  46. ne.textContent = 'Edit Tag';
  47. ne.href = '/tag/edit/'+ v[0].id;
  48. o.insertBefore(ne,p);
  49. o.insertBefore(document.createTextNode(' | '),p);
  50. ne = document.createElement('a');
  51. ne.textContent = 'Tag History';
  52. ne.href = '/history?search=tag:'+ v[0].id;
  53. o.insertBefore(ne,p);
  54. break;
  55. }
  56. o = o.nextElementSibling;
  57. }
  58. }
  59. }
  60. r.open('GET', location.protocol +'//'+ location.host + '/tag.json?limit=0&name='+ t, true);
  61. r.send();