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.2
  7. // ==/UserScript==
  8.  
  9. // Version 1.2
  10. // - even better matching code
  11. // Version 1.1
  12. // - wiki changes broke matching; changed method
  13. // Version 1.0.2
  14. // - better matching code
  15. // Version 1.0.1
  16. // - trivial change to better match malformed effect text on the wiki
  17.  
  18. function findEffect(acq) {
  19. var ps = document.evaluate('//td[text()="You '+acq+' an effect: "]',document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
  20. for (var i=ps.snapshotLength-1;i>=0;i--) {
  21. var p = ps.snapshotItem(i);
  22. var pps = document.evaluate('b/a[@title]',p,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
  23. for (var j=pps.snapshotLength-1;j>=0;j--) {
  24. var pp = pps.snapshotItem(j);
  25. var u = 'http://kol.coldfront.net'+pp.getAttribute('href');
  26. //GM_log('found effect: '+(pp.innerHTML));
  27. getUrl(u,p.parentNode);
  28. }
  29. }
  30. }
  31.  
  32. function getUrl(u,p) {
  33. GM_xmlhttpRequest({
  34. method: "GET",
  35. url: u,
  36. headers: {
  37. "User-Agent": "Mozilla/5.0",
  38. "Accept": "text/xml"
  39. },
  40. onload: function(response) {
  41. var m = response.responseText.match(/\<(p|span)\s*style=\"[^\"\>]*color:blue;\s*font-weight:bold;\s*\"\>.*/i);
  42. if (m) {
  43. //GM_log('m='+m);
  44. var t = m[1];
  45. m = m[0];
  46. var r = new RegExp('\<(/?'+t+')( |\>)','ig');
  47. var mm = r.exec(m);
  48. var count = 0;
  49. var last = 0;
  50. while (mm) {
  51. if (mm[1]==t) count++;
  52. else {
  53. count--;
  54. if (count==0) {
  55. last = r.lastIndex;
  56. break;
  57. }
  58. }
  59. mm = r.exec(m);
  60. }
  61. var eff = m.substring(0,last);
  62. //GM_log("found the effect: "+eff);
  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. //GM_log('creating font with innerHTML: '+f.innerHTML);
  67. var tr = document.createElement('tr');
  68. //var tr = tb.insertRow(-1);
  69. var td = tr.insertCell(-1);
  70. td.setAttribute('colspan','2');
  71. td.appendChild(f);
  72. if (p.nextSibling)
  73. p.parentNode.insertBefore(tr,p.nextSibling);
  74. else
  75. p.parentNode.appendChild(tr);
  76. } else
  77. GM_log('cannot find effect: '+response.responseText);
  78. }
  79. });
  80. }
  81.  
  82. findEffect('acquire');
  83. findEffect('lose');