Files
GoodnotesExportAll/userscript.js
2024-12-14 14:16:48 +01:00

72 lines
2.6 KiB
JavaScript

// ==UserScript==
// @name Goodnotes Export All
// @namespace http://tampermonkey.net/
// @version 2024-12-14
// @description Button to export all documents in current folder as pdf
// @author AINDUSTRIES
// @match https://web.goodnotes.com/home
// @icon https://www.google.com/s2/favicons?sz=64&domain=goodnotes.com
// @grant none
// @downloadURL https://raw.githubusercontent.com/A-INDUSTRIES/BetterMoodle/main/userscript.js
// @updateURL https://raw.githubusercontent.com/A-INDUSTRIES/BetterMoodle/main/userscript.js
// ==/UserScript==
(function() {
'use strict';
addButtonToUi();
})();
function addButtonToUi() {
let button = document.getElementById("library-top-bar-new-button");
if (button === null) {
setTimeout(() => {addButtonToUi();}, 100);
}
let newButton = document.createElement("button");
let separator = document.createElement("div");
newButton.textContent = "Export All";
newButton.className = "sc-11sl4ep-0 sc-11sl4ep-3 sc-11sl4ep-4 TWXtr jvQTin dtaHTu sc-1w3an16-5 jcbUh";
newButton.style.color = "white";
newButton.style.fontSize = "85%";
separator.className = "sc-1w3an16-8 dAJWSd";
button.parentNode.insertBefore(newButton, button.nextSibling);
button.parentNode.insertBefore(separator, button.nextSibling);
newButton.addEventListener("click", () => {
let allDocuments = getAllDocuments();
clickExportOnAllDocuments(allDocuments);
})
}
function getAllDocuments () {
let allDocuments = [];
let rootNode = document.getElementById("libraryViewDocumentGrid");
let childNodes = rootNode.childNodes;
childNodes.forEach((childNode) => {
// If the elements are documents they should not have an id.
if (childNode.getAttibute("id") === null) {
let child = childNode.firstChild;
allDocuments.push(child);
}
})
return allDocuments;
}
function clickExportOnAllDocuments(allDocuments) {
let i = 0;
allDocuments.forEach((doc) => {
let event = new MouseEvent('contextmenu', {
bubbles: true,
cancelable: true,
view: window,
button: 2
});
setTimeout(() => {
doc.dispatchEvent(event);
// Then get the context menu to click on "Export" after short delay
let exportButton = document.getElementById("exportPdfButton");
exportButton.click();
// Click out of context menu to allow other context menu to pop
let outer = document.getElementById("fullScreenModalDismissibleArea");
outer.click();
}, 500*i);
})
}