//META{"name":"OCR"}*//
class OCR {
get local() {
return {
startMessage: "${pluginName} ${version} has started.",
description: 'Optical character recognition. (Image to text)',
reset: "Reset settings",
settings: {
panel: 'Settings panel',
labels: {
apikey: 'Apikey'
},
help: {},
protip: {
label: 'Protip:',
tip: 'Register for an apikey here. (500 calls/day) https://ocr.space/ocrapi'
}
}
};
}
getAuthor() {
return "Arhippa"
}
getName() {
return "OCR"
}
getDescription() {
return this.local.description
}
getVersion() {
return "0.2"
}
start() {
if (!document.getElementById(`${this.getName()}-style`)) BdApi.injectCSS(`${this.getName()}-style`, this.css.thumb);
let libraryScript = document.getElementById('ZLibraryScript');
if (typeof window.ZLibrary !== "undefined") this.initialize();
else libraryScript.addEventListener('load', () => this.initialize());
}
initialize() {
if (settingsCookie['fork-ps-2'] === false) ZLibrary.Toasts.show(ZLibrary.Utilities.formatTString(this.local.startMessage, {
pluginName: this.getName(),
version: this.getVersion()
}));
this.initialized = true;
this.loadSettings();
this.injectThumbIcons();
}
stop() {
if (document.getElementById(`${this.getName()}-style`)) BdApi.clearCSS(`${this.getName()}-style`);
this.RemoveThumbIcons();
this.initialized = false;
}
load() {
let libraryScript = document.getElementById('ZLibraryScript');
if (!ZLibrary && !libraryScript) {
libraryScript = document.createElement('script');
libraryScript.setAttribute('type', 'text/javascript');
libraryScript.addEventListener("error", function() {
if (typeof ZLibrary === "undefined") {
window.BdApi.alert("Library Missing", `The library plugin needed for ${this.getName()} is missing and could not be loaded.
Click here to download the library!`);
}
}.bind(this));
libraryScript.setAttribute('src', 'https://rauenzi.github.io/BDPluginLibrary/release/ZLibrary.js');
libraryScript.setAttribute('id', 'ZLibraryScript');
document.head.appendChild(libraryScript);
}
}
unload() {}
injectThumbIcons() {
var fs = require('fs');
let list = document.querySelectorAll("img");
for (let i = 0; i < list.length; i++) {
let elem = list[i].parentElement;
if (!elem.href ||
!elem.classList.contains('imageWrapper-2p5ogY') ||
elem.querySelector('.thumbOCR')
) continue;
let div = document.createElement('div');
div.innerHTML = "OCR";
div.className = "thumbOCR";
this.loadSettings();
div.onclick = (e) => {
e.stopPropagation();
e.preventDefault();
this.doOCR(e);
};
elem.insertAdjacentElement('afterbegin', div);
}
this.injectionTimeout = setTimeout(this.injectThumbIcons.bind(this), 2000);
}
RemoveThumbIcons() {
clearTimeout(this.injectionTimeout);
$('div.thumbOCR').each(function(i, obj) {
$(this).remove();
});
}
saveSettings() {
ZLibrary.PluginUtilities.saveSettings(this.getName(), this.settings);
}
loadSettings() {
this.settings = ZLibrary.PluginUtilities.loadSettings(this.getName(), this.defaultSettings);
}
getSettingsPanel() {
let panel = $("