Skip to content

Commit

Permalink
fix for web interface versions V3.11+ (#6)
Browse files Browse the repository at this point in the history
* fix for new web interface versions

fixes #5

* use userscript syntax

---------

Co-authored-by: rM-self-serve <[email protected]>
  • Loading branch information
spencerpogo and rM-self-serve authored Jul 1, 2024
1 parent 9451f1f commit a5f2eac
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions webinterface-upload-button.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
// https://github.com/rM-self-serve/webinterface-upload-button

async function wait4header() {
for (let i=0; i<20; i++) {
const hgroups = document.getElementsByClassName('header-group');
if (hgroups.length > 1) {
return hgroups;
}
await new Promise(r => setTimeout(r, 100))
}
return null;
}

async function init() {
var css = `.header-button-ovrd {
(function() {
'use strict';

let global_is_uploading = false;

function init() {
var css = `.header-button-ovrd {
background-color: transparent;
};`;
var style = document.createElement('style');
Expand All @@ -22,8 +17,8 @@ async function init() {
style.appendChild(document.createTextNode(css));
}
document.getElementsByTagName('head')[0].appendChild(style);
const hgroups = await wait4header();

const hgroups = document.getElementsByClassName('header-group');
const my_files_box = hgroups[0];
my_files_box.style.flex = "10 1 auto";

Expand All @@ -33,25 +28,31 @@ async function init() {
let upbtn_node = document.createElement("a");
upbtn_node.role = "button";
upbtn_node.id = "upbtn";
upbtn_node.className = hbtn_elm.classList[0];
upbtn_node.appendChild(hbtn_elm.firstChild.cloneNode(true));
upbtn_node.className = hbtn_elm ? hbtn_elm.classList[0] : "header-button";
if (hbtn_elm) {
upbtn_node.appendChild(hbtn_elm.firstChild.cloneNode(true));
} else {
const i = document.createElement("i");
i.className = "icon-rm_ikoner_final_action_download-98";
const div = document.createElement("div");
div.appendChild(i);
upbtn_node.appendChild(div);
}
upbtn_node.classList.add("header-button-ovrd")
upbtn_node.style.borderWidth = "0px 0px 0px 1px";

let icon_elm = upbtn_node.firstChild.firstChild;
icon_elm.style.transform = "rotate(180deg)";

btns_elm.insertBefore(upbtn_node, hbtn_elm);

upbtn_node.addEventListener("click", handleSubmit);
}

let global_is_uploading = false;

async function handleSubmit(_) {
if (global_is_uploading) {
return;
}
global_is_uploading = true;
let input = document.createElement('input');
input.type = 'file';
input.multiple = true;
Expand All @@ -61,7 +62,6 @@ async function handleSubmit(_) {
}

async function input_auto_submit(input) {
global_is_uploading = true;
let list_elm = document.getElementsByClassName('list')[0];
let list_ref = list_elm.removeChild(list_elm.childNodes[1]);
let loaderNode = document.createElement("div");
Expand Down Expand Up @@ -151,5 +151,13 @@ function create_list_entry(file_name) {
return outer_div;
}

const callback = _ => {
if (document.getElementsByClassName("header-group").length >= 2) {
observer.disconnect();
init();
}
};

init()
const observer = new MutationObserver(callback);
observer.observe(document.body, {childList: true, subtree: true});
})();

0 comments on commit a5f2eac

Please sign in to comment.