assets

Wenku8++ used assets

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/449712/1094329/assets.js

  1. /* eslint-disable no-multi-spaces */
  2. /* eslint-disable userscripts/no-invalid-headers */
  3. /* eslint-disable userscripts/no-invalid-grant */
  4. /* eslint-disable no-implicit-globals */
  5.  
  6. // ==UserScript==
  7. // @name assets
  8. // @namespace Wenku8++
  9. // @version 0.1.4
  10. // @description Wenku8++ basic assets support
  11. // @author PY-DNG
  12. // @license GPL-v3
  13. // @regurl https?://www\.wenku8\.net/.*
  14. // @protect
  15. // ==/UserScript==
  16.  
  17. (function() {
  18. const FLAG = {
  19. SYSTEM: 1,
  20. NO_UNINSTALL: 2,
  21. NO_DISABLE: 4
  22. };
  23. const ClassName = {
  24. Button: 'plus_btn',
  25. Text: 'plus_text',
  26. Disabled: 'plus_disabled'
  27. };
  28. const URL = {};
  29. const Color = {
  30. Text: 'rgb(30, 100, 220)',
  31. Button: 'rgb(0, 160, 0)',
  32. ButtonHover: 'color: rgb(0, 100, 0)',
  33. ButtonFocus: 'color: rgb(0, 100, 0)',
  34. ButtonDisabled: 'rgba(150, 150, 150)',
  35. };
  36. const CSS = {
  37. Button_Text_Disabled: `.${ClassName.Text} {color: ${Color.Text} !important;} .${ClassName.Button} {color: ${Color.Button} !important; cursor: pointer !important; user-select: none;} .${ClassName.Button}:hover {${Color.ButtonHover} !important;} .${ClassName.Button}:focus {${Color.ButtonFocus} !important;} .${ClassName.Button}.${ClassName.Disabled} {color: ${Color.ButtonDisabled} !important; cursor: not-allowed !important;}`
  38. };
  39. const Number = {
  40. Interval: 500
  41. };
  42. const Text = {
  43. 'zh-CN': {}
  44. };
  45.  
  46. // Init language
  47. let i18n = navigator.language;
  48. let i18n_default = 'zh-CN';
  49. if (!Object.keys(Text).includes(i18n)) {i18n = i18n_default;}
  50.  
  51. // Common css
  52. addStyle(CSS.Button_Text_Disabled);
  53.  
  54. // Export
  55. exports = {
  56. FLAG: FLAG,
  57. ClassName: ClassName,
  58. URL: URL,
  59. Color: Color,
  60. CSS: CSS,
  61. Number: Number,
  62. Text: Text[i18n],
  63. Text_Full: Text
  64. }
  65.  
  66. // Append a style text to document(<head>) with a <style> element
  67. function addStyle(css, id) {
  68. const style = document.createElement("style");
  69. id && (style.id = id);
  70. style.textContent = css;
  71. for (const elm of document.querySelectorAll('#' + id)) {
  72. elm.parentElement && elm.parentElement.removeChild(elm);
  73. }
  74. document.head.appendChild(style);
  75. }
  76. }) ();