Greasy Fork is available in English.

KameSame Open Framework - Injector module

Injector module for KameSame Open Framework

Този скрипт не може да бъде инсталиран директно. Това е библиотека за други скриптове и може да бъде използвана с мета-директива // @require https://update.greasyfork.org/scripts/454425/1114503/KameSame%20Open%20Framework%20-%20Injector%20module.js

  1. "use strict";
  2. // ==UserScript==
  3. // @name KameSame Open Framework - Injector module
  4. // @namespace timberpile
  5. // @description Injector module for KameSame Open Framework
  6. // @version 0.0.0.1
  7. // @copyright 2022+, Timberpile
  8. // @license MIT; http://opensource.org/licenses/MIT
  9. // ==/UserScript==
  10.  
  11. (async (global) => {
  12. const ksof = global.ksof;
  13. await ksof.ready('document');
  14. class Section {
  15. constructor(title) {
  16. this.html = document.createElement('div');
  17. this.header = {
  18. html: ksof.pageInfo.on !== 'item_page' ? document.createElement('h2') : document.createElement('h3'),
  19. };
  20. this.header.html.innerText = title;
  21. this.html.appendChild(this.header.html);
  22. }
  23. }
  24. class SettingsSection extends Section {
  25. constructor(title, onclick) {
  26. super(title);
  27. this.settingsButton = {
  28. html: document.createElement('i'),
  29. };
  30. this.settingsButton.html.textContent = '⚙';
  31. this.settingsButton.html.setAttribute('class', 'fa fa-gear');
  32. this.settingsButton.html.setAttribute('style', 'cursor: pointer; vertical-align: middle; margin-left: 10px;');
  33. if (onclick) {
  34. this.settingsButton.html.onclick = onclick;
  35. }
  36. this.header.html.append(this.settingsButton.html);
  37. }
  38. }
  39. const addSection = (section) => {
  40. switch (ksof.pageInfo.on) {
  41. case 'item_page':
  42. {
  43. document.querySelector('#app.kamesame #item')?.appendChild(section.html);
  44. }
  45. break;
  46. case 'review':
  47. {
  48. document.querySelector('.outcome')?.appendChild(section.html);
  49. }
  50. break;
  51. default:
  52. {
  53. return undefined;
  54. }
  55. break;
  56. }
  57. return section;
  58. };
  59. ksof.Injector = {
  60. addSection: (title) => {
  61. return addSection(new Section(title));
  62. },
  63. addSettingsSection: (title, onclick) => {
  64. return addSection(new SettingsSection(title, onclick));
  65. },
  66. };
  67. // Notify listeners that we are ready.
  68. // Delay guarantees include() callbacks are called before ready() callbacks.
  69. setTimeout(() => { ksof.setState('ksof.Injector', 'ready'); }, 0);
  70. })(window);