DeepWiki

Adds an inline display of actual effects to acquired effects in potion and item descriptions on KoL wiki pages.

  1. // ==UserScript==
  2. // @name DeepWiki
  3. // @namespace kol.interface.unfinished
  4. // @description Adds an inline display of actual effects to acquired effects in potion and item descriptions on KoL wiki pages.
  5. // @include http://kol.coldfront.net/thekolwiki*
  6. // @version 1.21
  7. // @grant GM_xmlhttpRequest
  8. // ==/UserScript==
  9.  
  10. // Version 1.21
  11. // - add @grant
  12. // Version 1.2
  13. // - even better matching code
  14. // Version 1.1
  15. // - wiki changes broke matching; changed method
  16. // Version 1.0.2
  17. // - better matching code
  18. // Version 1.0.1
  19. // - trivial change to better match malformed effect text on the wiki
  20.  
  21. function findEffect(acq) {
  22. var ps = document.evaluate('//td[text()="You '+acq+' an effect: "]',document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
  23. for (var i=ps.snapshotLength-1;i>=0;i--) {
  24. var p = ps.snapshotItem(i);
  25. var pps = document.evaluate('b/a[@title]',p,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
  26. for (var j=pps.snapshotLength-1;j>=0;j--) {
  27. var pp = pps.snapshotItem(j);
  28. var u = 'http://kol.coldfront.net'+pp.getAttribute('href');
  29. getUrl(u,p.parentNode);
  30. }
  31. }
  32. }
  33.  
  34. function getUrl(u,p) {
  35. GM_xmlhttpRequest({
  36. method: "GET",
  37. url: u,
  38. headers: {
  39. "User-Agent": "Mozilla/5.0",
  40. "Accept": "text/xml"
  41. },
  42. onload: function(response) {
  43. var m = response.responseText.match(/\<(p|span)\s*style=\"[^\"\>]*color:blue;\s*font-weight:bold;\s*\"\>.*/i);
  44. if (m) {
  45. var t = m[1];
  46. m = m[0];
  47. var r = new RegExp('\<(/?'+t+')( |\>)','ig');
  48. var mm = r.exec(m);
  49. var count = 0;
  50. var last = 0;
  51. while (mm) {
  52. if (mm[1]==t) count++;
  53. else {
  54. count--;
  55. if (count==0) {
  56. last = r.lastIndex;
  57. break;
  58. }
  59. }
  60. mm = r.exec(m);
  61. }
  62. var eff = m.substring(0,last);
  63. var f = document.createElement('font');
  64. f.setAttribute('size','1');
  65. f.innerHTML='<p style="text-align:center;line-height:12px;">'+eff+'</p>';
  66. var tr = document.createElement('tr');
  67. var td = tr.insertCell(-1);
  68. td.setAttribute('colspan','2');
  69. td.appendChild(f);
  70. if (p.nextSibling)
  71. p.parentNode.insertBefore(tr,p.nextSibling);
  72. else
  73. p.parentNode.appendChild(tr);
  74. }
  75. }
  76. });
  77. }
  78.  
  79. findEffect('acquire');
  80. findEffect('lose');