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-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name jQuery and common function shortcuts everywhere
  3. // @namespace https://github.com/Alistair1231/my-userscripts/
  4. // @version 0.4.6
  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. ------------------------------------------\\n\
  26. '
  27. `;
  28.  
  29. const shortcuts = `
  30. const al = {
  31. help: () => console.log(${helpString}),
  32. cl: (str) => console.log(str),
  33. js: (obj) => JSON.stringify(obj),
  34. jsp: (obj) => JSON.stringify(obj, null, 2),
  35. jp: (str) => JSON.parse(str),
  36. qs: (selector) => document.querySelector(selector),
  37. qsa: (selector) => document.querySelectorAll(selector),
  38. gid: (id) => document.getElementById(id)
  39. };
  40. `;
  41.  
  42. const e = document.createElement('script');
  43. e.id = 'injectedScript';
  44. e.innerText = shortcuts;
  45. document.head.appendChild(e);
  46.  
  47. })();