Greasyfork - Add notes to the script

Add a note for scripts to help identify and search

As of 2020-09-09. See the latest version.

  1. // ==UserScript==
  2. // @name Greasyfork - Add notes to the script
  3. // @name:zh-CN Greasyfork - 为脚本添加备注
  4. // @name:zh-TW Greasyfork - 為腳本新增備註
  5. // @name:ja Greasyfork - スクリプトにコメントを追加
  6. // @name:ko Greasyfork - 스크립트에 메모 추가
  7. // @namespace https://greatest.deepsurf.us/zh-CN/users/193133-pana
  8. // @homepage https://www.sailboatweb.com
  9. // @icon data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjI0cHgiIGhlaWdodD0iMjRweCIgdmlld0JveD0iMCAwIDI0IDI0IiBhcmlhLWxhYmVsbGVkYnk9Im5ld0ljb25UaXRsZSIgc3Ryb2tlPSJyZ2JhKDI5LDE2MSwyNDIsMS4wMCkiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InNxdWFyZSIgc3Ryb2tlLWxpbmVqb2luPSJtaXRlciIgZmlsbD0ibm9uZSIgY29sb3I9InJnYmEoMjksMTYxLDI0MiwxLjAwKSI+IDx0aXRsZSBpZD0ibmV3SWNvblRpdGxlIj5OZXc8L3RpdGxlPiA8cGF0aCBkPSJNMTkgMTRWMjJIMi45OTk5N1Y0SDEzIi8+IDxwYXRoIGQ9Ik0xNy40NjA4IDQuMDM5MjFDMTguMjQxOCAzLjI1ODE3IDE5LjUwODIgMy4yNTgxNiAyMC4yODkyIDQuMDM5MjFMMjAuOTYwOCA0LjcxMDc5QzIxLjc0MTggNS40OTE4NCAyMS43NDE4IDYuNzU4MTcgMjAuOTYwOCA3LjUzOTIxTDExLjU4NTggMTYuOTE0MkMxMS4yMTA3IDE3LjI4OTMgMTAuNzAyIDE3LjUgMTAuMTcxNiAxNy41TDcuNSAxNy41TDcuNSAxNC44Mjg0QzcuNSAxNC4yOTggNy43MTA3MSAxMy43ODkzIDguMDg1NzkgMTMuNDE0MkwxNy40NjA4IDQuMDM5MjFaIi8+IDxwYXRoIGQ9Ik0xNi4yNSA1LjI1TDE5Ljc1IDguNzUiLz4gPC9zdmc+
  10. // @version 2.0.4
  11. // @description Add a note for scripts to help identify and search
  12. // @description:zh-CN 为脚本添加备注功能,以帮助识别和搜索
  13. // @description:zh-TW 為腳本新增備註功能,以幫助識別和搜尋
  14. // @description:ja スクリプトにコメント機能を追加して、識別と検索を支援します
  15. // @description:ko 식별 및 검색에 도움이되도록 스크립트에 메모 추가
  16. // @author pana
  17. // @license GNU General Public License v3.0 or later
  18. // @include http*://*greatest.deepsurf.us/*
  19. // @include http*://*sleazyfork.org/*
  20. // @require https://cdn.jsdelivr.net/npm/vue@2.6.11/dist/vue.min.js
  21. // @require https://greatest.deepsurf.us/scripts/408454-note-obj/code/Note_Obj.js?version=846245
  22. // @grant GM_info
  23. // @grant GM_getValue
  24. // @grant GM_setValue
  25. // @grant GM_deleteValue
  26. // @grant GM_listValues
  27. // @grant GM_registerMenuCommand
  28. // @grant GM_unregisterMenuCommand
  29. // @grant GM_addValueChangeListener
  30. // @grant GM_openInTab
  31. // ==/UserScript==
  32.  
  33. (function() {
  34. 'use strict';
  35. const GF_ICON = {
  36. 'NOTE_BLACK': 'url(data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjI0cHgiIGhlaWdodD0iMjRweCIgdmlld0JveD0iMCAwIDI0IDI0IiBhcmlhLWxhYmVsbGVkYnk9Im5ld0ljb25UaXRsZSIgc3Ryb2tlPSJyZ2IoMzgsIDM4LCAzOCkiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InNxdWFyZSIgc3Ryb2tlLWxpbmVqb2luPSJtaXRlciIgZmlsbD0ibm9uZSIgY29sb3I9InJnYigzOCwgMzgsIDM4KSI+IDx0aXRsZSBpZD0ibmV3SWNvblRpdGxlIj5OZXc8L3RpdGxlPiA8cGF0aCBkPSJNMTkgMTRWMjJIMi45OTk5N1Y0SDEzIi8+IDxwYXRoIGQ9Ik0xNy40NjA4IDQuMDM5MjFDMTguMjQxOCAzLjI1ODE3IDE5LjUwODIgMy4yNTgxNiAyMC4yODkyIDQuMDM5MjFMMjAuOTYwOCA0LjcxMDc5QzIxLjc0MTggNS40OTE4NCAyMS43NDE4IDYuNzU4MTcgMjAuOTYwOCA3LjUzOTIxTDExLjU4NTggMTYuOTE0MkMxMS4yMTA3IDE3LjI4OTMgMTAuNzAyIDE3LjUgMTAuMTcxNiAxNy41TDcuNSAxNy41TDcuNSAxNC44Mjg0QzcuNSAxNC4yOTggNy43MTA3MSAxMy43ODkzIDguMDg1NzkgMTMuNDE0MkwxNy40NjA4IDQuMDM5MjFaIi8+IDxwYXRoIGQ9Ik0xNi4yNSA1LjI1TDE5Ljc1IDguNzUiLz4gPC9zdmc+)'
  37. };
  38. const GF_STYLE = `
  39. .note-obj-gf-note-btn {
  40. background-image: ${GF_ICON.NOTE_BLACK};
  41. background-repeat: no-repeat;
  42. background-position: center;
  43. cursor: pointer;
  44. vertical-align: top;
  45. }
  46. .note-obj-gf-info-note-btn {
  47. background-size: 32px auto;
  48. width: 32px;
  49. height: 32px;
  50. margin-left: 20px;
  51. display: inline-block;
  52. }
  53. .note-obj-gf-library-note-btn {
  54. background-size: 24px auto;
  55. width: 24px;
  56. height: 24px;
  57. margin-left: 20px;
  58. display: inline-block;
  59. }
  60. .note-obj-gf-list-note-btn {
  61. background-size: 24px auto;
  62. width: 24px;
  63. height: 24px;
  64. margin-left: 10px;
  65. display: none;
  66. }
  67. .note-obj-gf-ts-note-btn {
  68. background-size: 16px auto;
  69. width: 16px;
  70. height: 16px;
  71. margin-left: 10px;
  72. display: none;
  73. vertical-align: sub;
  74. }
  75. ol.script-list li:hover .note-obj-gf-list-note-btn,
  76. #script-table tbody tr:hover .note-obj-gf-ts-note-btn {
  77. display: inline-block;
  78. }
  79. .note-obj-gf-note-tag,
  80. .note-obj-gf-ts-note-tag {
  81. background-color: #3c81df;
  82. color: #fff;
  83. display: inline-block;
  84. align-items: center;
  85. white-space: nowrap;
  86. border-radius: 50px;
  87. padding: 0px 10px;
  88. }
  89. .note-obj-gf-list-note-tag {
  90. text-decoration: none;
  91. }
  92. `;
  93. function change_Event(note_obj, id = null) {
  94. let pathname = location.pathname;
  95. if (/^\/[\w-]+\/scripts\/\d+-/i.test(pathname)) {
  96. let script_id = /^\/[\w-]+\/scripts\/(\d+)-/i.exec(pathname)[1];
  97. let ele = document.querySelector('#script-info h2');
  98. ele && (! id || id == script_id) && note_obj.handler(script_id, ele, null, {
  99. 'add': 'span',
  100. 'class': 'note-obj-gf-note-tag'
  101. });
  102. } else if (/^\/[\w-]+\/scripts/i.test(pathname) || /^\/[\w-]+\/users\/\d+/i.test(pathname)) {
  103. let browse_list = document.querySelectorAll('ol.script-list li');
  104. for (let ele of browse_list) {
  105. let script_id = ele.getAttribute('data-script-id');
  106. if (script_id) {
  107. let header = ele.querySelector('article > h2 > a');
  108. header && (! id || id == script_id) && note_obj.handler(script_id, header, null, {
  109. 'add': 'span',
  110. 'class': ['note-obj-gf-note-tag', 'note-obj-gf-list-note-tag']
  111. });
  112. }
  113. }
  114. document.querySelectorAll('#script-table tbody tr').forEach(item => {
  115. let script_title = item.querySelector('.thetitle a');
  116. if (script_title) {
  117. let script_id = script_title.href.match(/\d+$/) && script_title.href.match(/\d+$/)[0];
  118. (! id || id == script_id) && note_obj.handler(script_id, script_title, null, {
  119. 'add': 'span',
  120. 'class': 'note-obj-gf-ts-note-tag'
  121. });
  122. }
  123. });
  124. }
  125. }
  126. function init_TS(note_obj) {
  127. document.querySelectorAll('#script-table tbody tr').forEach(item => {
  128. let script_title = item.querySelector('.thetitle a');
  129. if (script_title) {
  130. let script_id = script_title.href.match(/\d+$/) && script_title.href.match(/\d+$/)[0];
  131. let thetitle = item.querySelector('.thetitle');
  132. script_id && thetitle.appendChild(note_obj.createNoteBtn(script_id, script_title.textContent, ['note-obj-gf-note-btn', 'note-obj-gf-ts-note-btn']));
  133. note_obj.judgeUsers(script_id) && note_obj.handler(script_id, script_title, null, {
  134. 'add': 'span',
  135. 'class': 'note-obj-gf-ts-note-tag'
  136. });
  137. }
  138. });
  139. }
  140. function init() {
  141. let old_config = GM_getValue('greasyfork_config', null);
  142. if (old_config && old_config.scripts_array) {
  143. for (let item of old_config.scripts_array) {
  144. GM_setValue(item.id, {
  145. 'tag': item.tag
  146. });
  147. }
  148. GM_deleteValue('greasyfork_config');
  149. }
  150. let note_obj = new Note_Obj('myGreasyForkNote');
  151. note_obj.init({
  152. 'style': GF_STYLE,
  153. 'changeEvent': change_Event,
  154. 'script': {
  155. 'author': {
  156. 'name': 'pana',
  157. 'homepage': 'https://www.sailboatweb.com/'
  158. },
  159. 'address': 'https://greatest.deepsurf.us/scripts/404275',
  160. 'updated': '2020-9-9'
  161. },
  162. 'itemClick': key => 'https://greatest.deepsurf.us/scripts/' + key,
  163. 'type': 'script'
  164. });
  165. let pathname = location.pathname;
  166. if (/^\/[\w-]+\/scripts\/\d+-/i.test(pathname)) {
  167. let script_id = /^\/[\w-]+\/scripts\/(\d+)-/i.exec(pathname)[1];
  168. let install_help_link = document.querySelector('#install-area .install-help-link');
  169. let suggestion = document.querySelector('#script-feedback-suggestion');
  170. let script_name = (document.querySelector('header h2') && document.querySelector('header h2').textContent) || '';
  171. if (install_help_link) {
  172. install_help_link.after(note_obj.createNoteBtn(script_id, script_name, ['note-obj-gf-note-btn', 'note-obj-gf-info-note-btn']));
  173. } else if (suggestion) {
  174. suggestion.appendChild(note_obj.createNoteBtn(script_id, script_name, ['note-obj-gf-note-btn', 'note-obj-gf-library-note-btn']));
  175. }
  176. let ele = document.querySelector('#script-info h2');
  177. ele && note_obj.judgeUsers(script_id) && note_obj.handler(script_id, ele, null, {
  178. 'add': 'span',
  179. 'class': 'note-obj-gf-note-tag'
  180. });
  181. } else if (/^\/[\w-]+\/scripts/i.test(pathname) || /^\/[\w-]+\/users\/\d+/i.test(pathname)) {
  182. let browse_list = document.querySelectorAll('ol.script-list li');
  183. for (let ele of browse_list) {
  184. let script_id = ele.getAttribute('data-script-id');
  185. if (script_id) {
  186. let description = ele.querySelector('.description');
  187. if (description) {
  188. let script_name = (ele.querySelector('article > h2 > a') && ele.querySelector('article > h2 > a').textContent) || '';
  189. description.before(note_obj.createNoteBtn(script_id, script_name, ['note-obj-gf-note-btn', 'note-obj-gf-list-note-btn']));
  190. }
  191. let header = ele.querySelector('article > h2 > a');
  192. header && note_obj.judgeUsers(script_id) && note_obj.handler(script_id, header, null, {
  193. 'add': 'span',
  194. 'class': ['note-obj-gf-note-tag', 'note-obj-gf-list-note-tag']
  195. });
  196. }
  197. }
  198. init_TS(note_obj);
  199. let ts_tbody = document.querySelector('#script-table tbody');
  200. if (ts_tbody) {
  201. let observer = new MutationObserver(() => {
  202. init_TS(note_obj);
  203. });
  204. observer.observe(ts_tbody, {
  205. 'childList': true
  206. });
  207. }
  208. }
  209. }
  210. init();
  211. })();