KameSame Open Framework - Injector module

Injector module for KameSame Open Framework

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/454425/1114503/KameSame%20Open%20Framework%20-%20Injector%20module.js

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

"use strict";
// ==UserScript==
// @name        KameSame Open Framework - Injector module
// @namespace   timberpile
// @description Injector module for KameSame Open Framework
// @version     0.0.0.1
// @copyright   2022+, Timberpile
// @license     MIT; http://opensource.org/licenses/MIT
// ==/UserScript==

(async (global) => {
    const ksof = global.ksof;
    await ksof.ready('document');
    class Section {
        constructor(title) {
            this.html = document.createElement('div');
            this.header = {
                html: ksof.pageInfo.on !== 'item_page' ? document.createElement('h2') : document.createElement('h3'),
            };
            this.header.html.innerText = title;
            this.html.appendChild(this.header.html);
        }
    }
    class SettingsSection extends Section {
        constructor(title, onclick) {
            super(title);
            this.settingsButton = {
                html: document.createElement('i'),
            };
            this.settingsButton.html.textContent = '⚙';
            this.settingsButton.html.setAttribute('class', 'fa fa-gear');
            this.settingsButton.html.setAttribute('style', 'cursor: pointer; vertical-align: middle; margin-left: 10px;');
            if (onclick) {
                this.settingsButton.html.onclick = onclick;
            }
            this.header.html.append(this.settingsButton.html);
        }
    }
    const addSection = (section) => {
        switch (ksof.pageInfo.on) {
            case 'item_page':
                {
                    document.querySelector('#app.kamesame #item')?.appendChild(section.html);
                }
                break;
            case 'review':
                {
                    document.querySelector('.outcome')?.appendChild(section.html);
                }
                break;
            default:
                {
                    return undefined;
                }
                break;
        }
        return section;
    };
    ksof.Injector = {
        addSection: (title) => {
            return addSection(new Section(title));
        },
        addSettingsSection: (title, onclick) => {
            return addSection(new SettingsSection(title, onclick));
        },
    };
    // Notify listeners that we are ready.
    // Delay guarantees include() callbacks are called before ready() callbacks.
    setTimeout(() => { ksof.setState('ksof.Injector', 'ready'); }, 0);
})(window);