Greasyfork - Add notes to the script

Add a note for scripts to help identify and search

As of 09.09.2020. See ბოლო ვერსია.

  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.3
  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=846168
  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-list-note-btn {
  54. background-size: 24px auto;
  55. width: 24px;
  56. height: 24px;
  57. margin-left: 10px;
  58. display: none;
  59. }
  60. .note-obj-gf-ts-note-btn {
  61. background-size: 16px auto;
  62. width: 16px;
  63. height: 16px;
  64. margin-left: 10px;
  65. display: none;
  66. vertical-align: sub;
  67. }
  68. ol.script-list li:hover .note-obj-gf-list-note-btn,
  69. #script-table tbody tr:hover .note-obj-gf-ts-note-btn {
  70. display: inline-block;
  71. }
  72. .note-obj-gf-note-tag,
  73. .note-obj-gf-ts-note-tag {
  74. background-color: #3c81df;
  75. color: #fff;
  76. display: inline-block;
  77. align-items: center;
  78. white-space: nowrap;
  79. border-radius: 50px;
  80. padding: 0px 10px;
  81. }
  82. .note-obj-gf-list-note-tag {
  83. text-decoration: none;
  84. }
  85. `;
  86. function change_Event(note_obj, id = null) {
  87. let pathname = location.pathname;
  88. if (/^\/[\w-]+\/scripts\/\d+-/i.test(pathname)) {
  89. let script_id = /^\/[\w-]+\/scripts\/(\d+)-/i.exec(pathname)[1];
  90. let ele = document.querySelector('#script-info h2');
  91. ele && (! id || id == script_id) && note_obj.handler(script_id, ele, null, {
  92. 'add': 'span',
  93. 'class': 'note-obj-gf-note-tag'
  94. });
  95. } else if (/^\/[\w-]+\/scripts/i.test(pathname) || /^\/[\w-]+\/users\/\d+/i.test(pathname)) {
  96. let browse_list = document.querySelectorAll('ol.script-list li');
  97. for (let ele of browse_list) {
  98. let script_id = ele.getAttribute('data-script-id');
  99. if (script_id) {
  100. let header = ele.querySelector('article > h2 > a');
  101. header && (! id || id == script_id) && note_obj.handler(script_id, header, null, {
  102. 'add': 'span',
  103. 'class': ['note-obj-gf-note-tag', 'note-obj-gf-list-note-tag']
  104. });
  105. }
  106. }
  107. document.querySelectorAll('#script-table tbody tr').forEach(item => {
  108. let script_title = item.querySelector('.thetitle a');
  109. if (script_title) {
  110. let script_id = script_title.href.match(/\d+$/) && script_title.href.match(/\d+$/)[0];
  111. (! id || id == script_id) && note_obj.handler(script_id, script_title, null, {
  112. 'add': 'span',
  113. 'class': 'note-obj-gf-ts-note-tag'
  114. });
  115. }
  116. });
  117. }
  118. }
  119. function init_TS(note_obj) {
  120. document.querySelectorAll('#script-table tbody tr').forEach(item => {
  121. let script_title = item.querySelector('.thetitle a');
  122. if (script_title) {
  123. let script_id = script_title.href.match(/\d+$/) && script_title.href.match(/\d+$/)[0];
  124. let thetitle = item.querySelector('.thetitle');
  125. script_id && thetitle.appendChild(note_obj.createNoteBtn(script_id, script_title.textContent, ['note-obj-gf-note-btn', 'note-obj-gf-ts-note-btn']));
  126. note_obj.judgeUsers(script_id) && note_obj.handler(script_id, script_title, null, {
  127. 'add': 'span',
  128. 'class': 'note-obj-gf-ts-note-tag'
  129. });
  130. }
  131. });
  132. }
  133. function init() {
  134. let old_config = GM_getValue('greasyfork_config', null);
  135. if (old_config && old_config.scripts_array) {
  136. for (let item of old_config.scripts_array) {
  137. GM_setValue(item.id, {
  138. 'tag': item.tag
  139. });
  140. }
  141. GM_deleteValue('greasyfork_config');
  142. }
  143. let note_obj = new Note_Obj('myGreasyForkNote');
  144. note_obj.init({
  145. 'style': GF_STYLE,
  146. 'changeEvent': change_Event,
  147. 'script': {
  148. 'author': {
  149. 'name': 'pana',
  150. 'homepage': 'https://www.sailboatweb.com/'
  151. },
  152. 'address': 'https://greatest.deepsurf.us/scripts/404275',
  153. 'updated': '2020-9-9'
  154. },
  155. 'itemClick': key => 'https://greatest.deepsurf.us/scripts/' + key,
  156. 'type': 'script'
  157. });
  158. let pathname = location.pathname;
  159. if (/^\/[\w-]+\/scripts\/\d+-/i.test(pathname)) {
  160. let script_id = /^\/[\w-]+\/scripts\/(\d+)-/i.exec(pathname)[1];
  161. let install_help_link = document.querySelector('#install-area .install-help-link');
  162. if (install_help_link) {
  163. let script_name = (document.querySelector('header h2') && document.querySelector('header h2').textContent) || '';
  164. install_help_link.after(note_obj.createNoteBtn(script_id, script_name, ['note-obj-gf-note-btn', 'note-obj-gf-info-note-btn']));
  165. }
  166. let ele = document.querySelector('#script-info h2');
  167. ele && note_obj.judgeUsers(script_id) && note_obj.handler(script_id, ele, null, {
  168. 'add': 'span',
  169. 'class': 'note-obj-gf-note-tag'
  170. });
  171. } else if (/^\/[\w-]+\/scripts/i.test(pathname) || /^\/[\w-]+\/users\/\d+/i.test(pathname)) {
  172. let browse_list = document.querySelectorAll('ol.script-list li');
  173. for (let ele of browse_list) {
  174. let script_id = ele.getAttribute('data-script-id');
  175. if (script_id) {
  176. let description = ele.querySelector('.description');
  177. if (description) {
  178. let script_name = (ele.querySelector('article > h2 > a') && ele.querySelector('article > h2 > a').textContent) || '';
  179. description.before(note_obj.createNoteBtn(script_id, script_name, ['note-obj-gf-note-btn', 'note-obj-gf-list-note-btn']));
  180. }
  181. let header = ele.querySelector('article > h2 > a');
  182. header && note_obj.judgeUsers(script_id) && note_obj.handler(script_id, header, null, {
  183. 'add': 'span',
  184. 'class': ['note-obj-gf-note-tag', 'note-obj-gf-list-note-tag']
  185. });
  186. }
  187. }
  188. init_TS(note_obj);
  189. let ts_tbody = document.querySelector('#script-table tbody');
  190. if (ts_tbody) {
  191. let observer = new MutationObserver(() => {
  192. init_TS(note_obj);
  193. });
  194. observer.observe(ts_tbody, {
  195. 'childList': true
  196. });
  197. }
  198. }
  199. }
  200. init();
  201. })();