Echo Bazaar - Display Storylet Prerequisites

For Fallen London (previously Echo Bazaar) - Displays storylet prerequisites in plain text so that you can see the information at a glance without having to mouse over multiple icons to uncover it bit by bit.

当前为 2015-07-30 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Echo Bazaar - Display Storylet Prerequisites
  3. // @namespace http://arundor/echo.bazaar.disply.storylet.prerequisites
  4. // @description For Fallen London (previously Echo Bazaar) - Displays storylet prerequisites in plain text so that you can see the information at a glance without having to mouse over multiple icons to uncover it bit by bit.
  5. // @version 1.7
  6. // @include http://echobazaar.failbettergames.com/Gap/Load*
  7. // @include http://*fallenlondon.com/Gap/Load*
  8. // @include http://fallenlondon.storynexus.com/Gap/Load*
  9. // ==/UserScript==
  10.  
  11. /*
  12. I am an amateur script writer. What you see here is not necessarily the best way to achieve what has been done.
  13.  
  14. Changelog:
  15.  
  16. v.1.7
  17. July 29, 2015
  18. - updated to work after layout changes in the game
  19.  
  20. v1.6
  21. January 6, 2014
  22. - updated to work after layout changes in the game
  23. v1.5
  24. August 24, 2012
  25. - updated for the new fallenlondon.storynexus.com domain.
  26.  
  27. v1.4:
  28. May 27, 2012
  29. - requirements you have not met are now displayed in grey
  30. - updated script @description to reflect the game's new name (@name cannot be updated in the same way, as doing so would break the update process for users of the old version)
  31. - the @version meta data tag is now used
  32.  
  33. v1.3:
  34. March 26, 2012
  35. - now works on the new fallenlondon.com domain
  36.  
  37. v1.2:
  38. Jan 26, 2012
  39. - support for Google Chrome
  40. - removes item acquisition tips from the list of prerequisites
  41. - better method of preventing the script from running before Ajax has fully loaded the main content
  42. - better method of constructing the the new div that holds the plain text prereqs, this method prevents unnecessary nested divs.
  43. - prereq text now prints inside the storylet_rhs block to prevent clipping issues with the prereq icons
  44.  
  45. v1.1:
  46. Jan 24, 2012
  47. -initial release
  48. */
  49.  
  50.  
  51. //The main content of the page is loaded by Ajax so an action listener is used to detect it when it is inserted.
  52. document.addEventListener('DOMNodeInserted', showPrereqs, false);
  53.  
  54. //Due to the way the action listener is set up, this function may fire multiple times per storylet.
  55. //I know of no better way to handle this, but since it fires multiple times each iteration will need to check if a previous iteration has already done of the work of adding the plain text requirements list.
  56. function showPrereqs() {
  57. var qreqs = document.getElementsByClassName('qreqs');
  58. if (qreqs) {
  59. for (var a=0; a<qreqs.length; a++) {
  60. var parent = qreqs[a].parentNode.parentNode.getElementsByClassName('storylet_rhs')[0];
  61. if (parent) {
  62. //Each iteration of the script checks for the 'plain_text_reqs' class to determine if a previous iteration of the function has already done the work.
  63. if (parent.getElementsByClassName('plain_text_reqs').length == 0) {
  64. var tooltips = qreqs[a].getElementsByTagName('a');
  65.  
  66. //Constructing a new div element to hold the list of plain text requirements.
  67. //The class is set to 'plain_text_reqs' as a marker that future iterations of the function can look for to determine if the work is already done.
  68. var div = document.createElement('div');
  69. div.setAttribute('class', 'plain_text_reqs');
  70. div.style.fontSize = '65%';
  71. div.style.width = '100%';
  72. div.style.clear = 'both';
  73. div.style.paddingBottom = '10px';
  74. if (tooltips) {
  75. for (var b=0; b<tooltips.length; b++) {
  76. var text;
  77. if (tooltips[b].getElementsByClassName('tt')[0].getElementsByTagName('p')[0]) {
  78. text = tooltips[b].getElementsByClassName('tt')[0].getElementsByTagName('p')[0].innerHTML;
  79. }
  80. var wordy_list;
  81. var addon_text = '';
  82. if (tooltips[b].getElementsByClassName('wordy-list')[0]) {
  83. wordy_list = tooltips[b].getElementsByClassName('wordy-list')[0].getElementsByTagName('li');
  84. for (var c=0; c<wordy_list.length; c++) {
  85. if (wordy_list[c].innerHTML.substring(0,2) == '- ') {
  86. addon_text += '<br> &nbsp; &nbsp; &nbsp; &nbsp; -' + wordy_list[c].innerHTML.substring(2, wordy_list[c].innerHTML.length);
  87. }
  88. else {
  89. addon_text += '<br> &nbsp; &nbsp; &nbsp; &nbsp; -' + wordy_list[c].innerHTML;
  90. }
  91. if (wordy_list[c].getAttribute('class') != 'current') {
  92. addon_text = '<span style="color: grey">' + addon_text + '</span>';
  93. }
  94. }
  95. }
  96. if (addon_text.length > 0) {
  97. text += addon_text;
  98. }
  99. //If the requirement has not yet been met, display the text in grey.
  100. if (tooltips[b].getAttribute('class') == 'tooltip qreq unlock') {
  101. text = '<span style="color: grey">' + text + '</span>';
  102. }
  103. div.innerHTML += '<br>- ' + text;
  104. }
  105. }
  106. //Even if the new div is empty it is added to the page anyway.
  107. //This is done so that future iterations of the function can find it and know that the work is already done.
  108. parent.appendChild(div);
  109. }
  110. }
  111. }
  112. }
  113. }