From 1aa597392c44106ce43065688b4c2cdf0f4d0339 Mon Sep 17 00:00:00 2001 From: AINDUSTRIES Date: Sat, 14 Dec 2024 14:16:48 +0100 Subject: [PATCH] V1 --- README.md | 3 +++ userscript.js | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 README.md create mode 100644 userscript.js diff --git a/README.md b/README.md new file mode 100644 index 0000000..65c5c84 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Goodnotes Export All +### This a small userscript to add the ability to export all documents visible on the page at once. +### This is useful to bulk export folders \ No newline at end of file diff --git a/userscript.js b/userscript.js new file mode 100644 index 0000000..8384ed0 --- /dev/null +++ b/userscript.js @@ -0,0 +1,72 @@ +// ==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); + }) +} \ No newline at end of file