Greasy Fork 还支持 简体中文。

jQuery and common function shortcuts everywhere

injects jquery if not exists and adds some common function shortcuts to the window object. See al.help() for details.

目前為 2023-04-29 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name jQuery and common function shortcuts everywhere
  3. // @namespace https://github.com/Alistair1231/my-userscripts/
  4. // @version 0.5
  5. // @description injects jquery if not exists and adds some common function shortcuts to the window object. See al.help() for details.
  6. // @author Alistair1231
  7. // @match *://*/*
  8. // @grant GM_xmlhttpRequest
  9. // @license GPL-3.0
  10. // ==/UserScript==
  11. // https://greasyfork.org/en/scripts/439017-jquery-and-common-function-shortcuts-everywhere
  12. (function () {
  13. 'use strict';
  14. const helpString = `
  15. '\
  16. al: jQuery and Method shortcuts everywhere\\n\
  17. ------------------------------------------\\n\
  18. al.cl(str) - console.log(str)\\n\
  19. al.js(obj) - JSON.stringify(obj)\\n\
  20. al.jsp(obj) - JSON.stringify(obj, null, 2)\\n\
  21. al.jp(str) - JSON.parse(str)\\n\
  22. al.qs(selector) - document.querySelector(selector)\\n\
  23. al.qsa(selector) - document.querySelectorAll(selector)\\n\
  24. al.gid(id) - document.getElementById(id)\\n\
  25. al.print() - Prints the object definition\\n\
  26. ------------------------------------------\\n\
  27. '
  28. `;
  29.  
  30. const shortcuts = `
  31. const al = {
  32. help: () => console.log(${helpString}),
  33. cl: (str) => console.log(str),
  34. js: (obj) => JSON.stringify(obj),
  35. jsp: (obj) => JSON.stringify(obj, null, 2),
  36. jp: (str) => JSON.parse(str),
  37. qs: (selector) => document.querySelector(selector),
  38. qsa: (selector) => document.querySelectorAll(selector),
  39. gid: (id) => document.getElementById(id),
  40. print: () => {
  41. const { help, ...rest } = al;
  42. console.log(rest);
  43. }
  44. };
  45. `;
  46.  
  47. const e = document.createElement('script');
  48. e.id = 'injectedScript';
  49. e.innerText = shortcuts;
  50.  
  51.  
  52. document.head.appendChild(e);
  53.  
  54. })();