Created
February 14, 2025 02:33
-
-
Save SpaceSaver/20e46214155ba30fa73a3443637782a3 to your computer and use it in GitHub Desktop.
Changes the parent folder name to a link in document info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Docs Parent Linking | |
// @namespace https://github.com/SpaceSaver | |
// @version 2025-02-12 | |
// @description try to take over the world! | |
// @author u/SpaceSaver2000-1 | |
// @match https://docs.google.com/*/d/*/edit* | |
// @icon https://docs.google.com/favicon.ico | |
// @run-at document-idle | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
async function inject(parent_id) { | |
let locelem = null; | |
try { | |
locelem = document.querySelector("[jsname='oKdM2c']").children[1]; | |
} catch {} | |
if (!locelem || document.querySelector("#luke_i_am_your_father")) return null; | |
const drive_base = `https:${window._docs_flag_initialData.drive_url.split("?")[0].replace("drive.google.com/", "drive.google.com/drive/")}`; | |
if (parent_id != "/my-drive") { | |
parent_id = "/folders/" + parent_id; | |
} | |
const link = document.createElement("a"); | |
link.id = "luke_i_am_your_father"; | |
link.href = drive_base + parent_id; | |
link.setAttribute("target", "_blank"); | |
while (locelem.childNodes.length > 0) { | |
const child = locelem.childNodes[0]; | |
link.appendChild(child); | |
} | |
locelem.appendChild(link); | |
} | |
fetch(`${window._docs_flag_initialData.app_url.split("?")[0]}d/${window._docs_flag_initialData["docs-ci"]}/peruserchrome`).then(async resp => { | |
let realInfo = await resp.text(); | |
try { | |
realInfo = JSON.parse(realInfo.replaceAll("\r", "").split("\n")[1]); | |
let parent = null; | |
if (realInfo.PARENTS && realInfo.PARENTS.length > 0) { | |
parent = (realInfo.PARENTS[0].objectId); | |
} else if (realInfo.IS_IN_MY_DRIVE) { | |
parent = ("/my-drive"); | |
} else { | |
return; | |
} | |
setInterval(() => {inject(parent)}, 500) | |
} catch (e) { | |
console.log("Issues were encountered", e) | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment