Greasyfork - Add notes to the script

Add a note(alias/tag) for scripts to help identify and search

Verze ze dne 11. 09. 2020. Zobrazit nejnovější verzi.

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