Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Add WPS document download shortcut button
- // @namespace https://greasyfork.org/en/users/85671-jcunews
- // @version 1.0.1
- // @license AGPL v3
- // @author jcunews
- // @description Add a shortcut button for the Download function of the main menu onto the document share page and the document page.
- // @match https://*.docs.wps.com/l/*
- // @match https://*.docs.wps.com/module/common/loadPlatform/*
- // @grant none
- // ==/UserScript==
- (() => {
- function check(btn, container) {
- if (location.pathname.startsWith("/module/") && (btn = document.querySelector('.btn.open-browser'))) { //share page
- btn.insertAdjacentHTML("beforeend", `<button id=dlbtn style="float:right">Download</button>`);
- btn.lastChild.onclick = () => sessionStorage.download = 1
- } else if (location.pathname.startsWith("/l/") && (container = document.querySelector('.component-header-file-info>.file-name'))) { //document page
- container.insertAdjacentHTML("beforeend", `<button id=dlbtn style="margin-left:.5em;padding:0 .3em">Download</button>`);
- container.lastChild.onclick = () => {
- document.querySelector('#component-header-left .header-more-btn>button').click();
- (function waitmenu() {
- if (btn = document.querySelector('.file-more-panel .menu-text[data-key="Download"]')) {
- btn.click()
- } else setTimeout(waitmenu, 200)
- })()
- };
- if (sessionStorage.download) {
- delete sessionStorage.download;
- (function waitmenubtn() {
- if (btn = document.querySelector('#component-header-left .header-more-btn>button')) {
- dlbtn.click();
- if (!btn.matches('.is-selected')) setTimeout(waitmenubtn, 200)
- } else setTimeout(waitmenubtn, 200)
- })()
- }
- }
- }
- check();
- (new MutationObserver(recs => {
- if (!window.dlbtn && recs.some(rec => rec.addedNodes.length > 0)) check()
- })).observe(document.body, {childList: true, subtree: true})
- })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement