Skip to content

Instantly share code, notes, and snippets.

@donnaken15
Last active April 17, 2024 10:54
Show Gist options
  • Save donnaken15/acf68b8f4c9dd561ad64a5295544715b to your computer and use it in GitHub Desktop.
Save donnaken15/acf68b8f4c9dd561ad64a5295544715b to your computer and use it in GitHub Desktop.
// or download from Drive link
// supports folders and archive files
// use https://script.google.com/macros/s/AKfycbzdUJB_KiUDSlCchIF13hXhwHs1ObagXJ_WSmToL7RzTUb7H_npEBiYmj3k4VKPW3Wr/dev?id=XXXXXXX
// or now: https://tinyurl.com/FGH3g?id=XXXXXXX
function runExample() {
doGet({
"parameter": {
"id": "1fh7KiIhbFhikP04JHkltwJ5Dnpw1KK-P" //1Ediig76MdWu_bXoAvWahmWdlqOxC56K8" //"1rwUD1rT4Pq6wTCNJ17E-3hRWouclDLtg" <--TOO BIG 1fh7KiIhbFhikP04JHkltwJ5Dnpw1KK-P
}
});
}
var hash = BigInt("0x5745534C45593634"),
hashrev = BigInt("0x343659454C534557");
function WZK64(data)
{
var _hash = hash;
for (var i=0;i<data.length;i++)
{
_hash ^= BigInt((data[i] << 56) >> ((i%8)*8));
}
_hash ^= BigInt(data.length) * BigInt(hashrev);
return _hash & BigInt("0xFFFFFFFFFFFFFFFF"); // getting weird 64 bit overflow
}
var timestart, time, log, dir = true,
html =
'<style>* {padding:1px; margin:1px; font-weight:400;\
font-family: monospace, Roboto Mono, Courier;}\
h1,h1 *{font-size:72px; padding:0; margin:0;}\
h2{font-size:64px;}\
div{font-size:40px;white-space:pre;}\
</style><h1>chorus for \
<!--wasteful but yoloswag-->\
<a style="color:#0f9">Fa</a>\
<a style="color:#f00">st</a>\
<a style="color:#ff0">G</a>\
<a style="color:#00f">H</a>\
<a style="color:#f80">3</a>\
</h1><h2>Log:</h2><br>',
htmlend = "";
// don't know a fitting function name
function timeToFlt(val) {
val='2000-01-01T'+val+'Z';
var date=new Date(new Date(val)-(new Date()).getTimezoneOffset() * 228000);
var time=(date.getHours()*3600)+(date.getMinutes()*60)+date.getSeconds()+(date.getMilliseconds()/1000);
return time;
}
function print(a)
{
log += "[" + ((Date.now()-timestart)/1000).toFixed(3).padStart(7) + "] " + a + "\n";
console.log(a);
}
// https://stackoverflow.com/questions/10744760/google-apps-script-to-open-a-url
function JS2OpenURL(url)
{
//print("<a href=\""+url+"\">Link</a>");
return '<script>var a = document.createElement("a"); a.href="'+url+'";'
+'if(document.createEvent){'
+' var event=document.createEvent("MouseEvents");'
+' if(navigator.userAgent.toLowerCase().indexOf("firefox")>-1){window.document.body.append(a)}'
+' event.initEvent("click",true,true); a.dispatchEvent(event);'
+'}else{ a.click() }</script>'
}
function cFGH3Link(id)
{
return 'fastgh3://drive.google.com/uc?id='+id+"&export=download&confirm=t";
}
function die(_html)
{
return HtmlService.createHtmlOutput(html+_html+htmlend);
}
function doGet(e) {
//Logger.log(e);
timestart = Date.now();
var cleanFolderSwitch = e.parameter.clean;
if (cleanFolderSwitch !== undefined)
{
print("Got clean param");
var FSPfolderName = "Z.FGH3$TMP";
var FSPfolderSearch = DriveApp.getFoldersByName(FSPfolderName), FSPfolder, scan;
if (FSPfolderSearch.hasNext())
{
//DriveApp.removeFolder(FSPfolderSearch.next()); // not working
FSPfolder = FSPfolderSearch.next();
scan = FSPfolder.getFilesByType("application/zip");
while (scan.hasNext())
{
scan.next().setTrashed(true);
// how do i permanently delete
}
print("Cleaned the FSP cache folder. (trashed)");
return die("<div>Cleaned the FSP cache folder. (trashed)</div>");
}
//else
{
console.error("The FSP cache folder does not exist.");
return die("<div>The FSP cache folder does not exist.</div>");
}
}
var __I = e.parameter.id;
if (__I === undefined || __I === "" || __I === null)
{
console.error("No file ID specified. Exiting.");
return die("<div>No file ID specified. Cancelling.</div>");
}
log = "";
var root, fileindex;
dir = false;
try
{
root = DriveApp.getFolderById(__I);
fileindex = root.getFiles();
dir = true;
}
catch
{
try
{
root = DriveApp.getFileById(__I);
dir = false;
}
catch
{
console.error("Error while getting folder/file.\nDoes it exist?\nExiting.");
return die("<div>Error while getting folder/file.<br>Does it exist?<br>Exiting.</div>");
}
}
if (root.getName().endsWith(".zip") ||
root.getName().endsWith(".rar") ||
root.getName().endsWith(".7z"))
{
root = DriveApp.getFileById(__I);
dir = false;
}
var files = [], curfile;
var FSPfolderName = "Z.FGH3$TMP";
var FSPfolderSearch = DriveApp.getFoldersByName(FSPfolderName), FSPfolder;
if (FSPfolderSearch.hasNext())
{
FSPfolder = FSPfolderSearch.next();
}
else
FSPfolder = DriveApp.createFolder(FSPfolderName);
if (!dir)
{
print("Archive file found.");
{
//print(root.getId());
if (root.getSharingPermission() != DriveApp.Permission.VIEW)
{
print("ERROR: Insufficient access to file. Cancelling.");
return HtmlService.createHtmlOutput(html+"<div>"+log.replaceAll("\n","<br>")+"</div>"+htmlend);
}
print("PLAY!");
htmlend += JS2OpenURL(cFGH3Link(root.getId()))
console.log("Run link: "+cFGH3Link(root.getId()))
return die("<div>"+log.replaceAll("\n","<br>")+"</div>");
}
}
var zipHash = BigInt(0);
while (fileindex.hasNext())
{
curfile = fileindex.next();
print("Getting file info for: "+curfile.getName());
zipHash ^= WZK64(curfile.getId()) ^ WZK64(curfile.getLastUpdated().getTime().toString());
files.unshift(curfile.getBlob());
}
var zipHashStr = (zipHash.toString(16).toUpperCase().padStart(16,"0"));
var fname = "FSP"+zipHashStr+".fsp";
var cacheSearch = FSPfolder.getFilesByName(fname);
while (cacheSearch.hasNext())
{
var cacheFile = cacheSearch.next();
if (cacheFile.getName() == fname)
{
print("Found cached ZIP.");
console.log(fname);
htmlend += JS2OpenURL(cFGH3Link(cacheFile.getId()))
console.log("Run link: "+cFGH3Link(cacheFile.getId()))
return die("<div>"+log.replaceAll("\n","<br>")+"</div>");
}
}
{
print("Creating ZIP.");
try {
var tmpfilec = Utilities.zip(files);
var tmpfile = DriveApp.createFile(tmpfilec), filename = fname;
tmpfile.moveTo(FSPfolder);
tmpfile.setName(filename);
tmpfile.setSharing(DriveApp.Access.ANYONE,DriveApp.Permission.VIEW); // just so the launcher can download it
}
catch (e) {
print("An error has occured while creating the ZIP.");
print(e);
return HtmlService.createHtmlOutput(html+"<div>"+log.replaceAll("\n","<br>")+"</div>"+htmlend);
}
}
print("PLAY!");
htmlend += JS2OpenURL(cFGH3Link(tmpfile.getId()))
console.log("Run link: "+cFGH3Link(tmpfile.getId()))
return die("<div>"+log.replaceAll("\n","<br>")+"</div>");
}
// ==UserScript==
// @name Chorus Encore for FastGH3 (buttons)
// @namespace https://donnaken15.com/
// @version 0.2
// @description burn your cookie dough and chocolate chips to a crisp, causing a housefire, extending to a forestfire
// @author Wesley
// @match https://www.enchor.us/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=enchor.us
// @grant none
// ==/UserScript==
function dive(e, d) {
'use strict';
var r = e;
var i;
if (typeof d === 'number')
for (i = 0; i < d; i++)
r = r.children[0];
else
for (i = 0; i < d.length; i++)
r = r.children[d[i]];
return r;
}
(function() {
'use strict';
var songs;
var updateFGH3Links = function() {
songs = document.getElementsByTagName("ce-search-result");
if (songs.length === 0) return;
for (var i=0; i < songs.length; i++)
{
if (songs[i].fast === undefined && songs[i].children.length > 0)
{
try {
var buttons = dive(songs[i], [1, 0, 0, 2]);
var fileinfo = dive(buttons.children[buttons.childElementCount - 1], [2, 1, 0, 0]);
switch (fileinfo.childElementCount)
{
case 2:
fileinfo = dive(fileinfo, [1, 0, 1]);
break;
case 3:
fileinfo = dive(fileinfo, [2, 0, 1]);
break;
}
var target = "";
var fname = "";
var singular = fileinfo.childElementCount === 1;
var aSP = false;
for (var j = 0; j < fileinfo.childElementCount; j++)
{
var file = fileinfo.children[j];
if (singular || dive(file, [0, 0]).checked || (aSP && !singular))
{
var findlink = dive(file, [5 - singular, 0, 0]);
var l = 0;
for (var k = findlink.childElementCount - 1; k >= 0; k--, l++)
{
var e = dive(findlink, [k]);
if (e.childElementCount > 0)
if (e.children[0].tagName.toLowerCase() === 'a')
{
fname = e.children[0].innerText;
target = e.children[0].href;
if (l > 0 && !singular)
aSP = true;
break;
}
if (aSP)
break;
}
if (aSP)
continue;
}
}
if (target === "")
{
console.error(fileinfo);
songs[i].fast = "1";
continue;
}
var folder =
!(fname.endsWith(".7z") ||
fname.endsWith(".rar") ||
fname.endsWith(".sng") ||
fname.endsWith(".zip"));
var driveId;
target = target.substr(target.indexOf("?id=")+4);
var ampcheck = target.indexOf("&");
if (ampcheck !== -1)
target = target.substr(0, ampcheck);
target = (folder ?
"https://tinyurl.com/FGH3g" :
"fastgh3://drive.google.com/uc"
) + "?id=" + target;
var button = document.createElement("div");
button.className = "ml-2";
button.innerHTML =
`<a target="_blank" href="`+target+`">`+
`<button class="btn btn-neutral text-xl" style="color: white;padding: 0.3em;">`+
`<div>Play in</div>`+
`<img class="w-20" src="`+
`data:image/svg+xml;base64,`+ // just to not bug my server every time for the logo
// TODO: use background-image(svg) ::before
`PHN2ZyB3aWR0aD0iMTAwMCIgaGVpZ2h0PSIyNTAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm`+
`9yZy8yMDAwL3N2ZyI+Cgk8dGl0bGU+RmFzdEdIMzwvdGl0bGU+Cgk8cGF0aCBmaWxsPSIj`+
`MGY5IiBkPSJtMjMyLjIgMjM5LjN2LTIyNS40aC0zOC4wN2wtODEuMzMgMTE1LjdoLTcwLj`+
`A3di03Ni43NWg3NS44M3YtMzguOTloLTExNy41djIyNS40aDg1LjI3bDQ4LjcyLTcwLjY0`+
`aDU1LjQ0djcwLjY0em0tNDEuNzQtMTA5LjdoLTI4LjkzbDI4LjMzLTQxLjQzaDAuNjA5em`+
`0tMTA1LjEgMzguOTktNDIuNjUgNjAuNnYtNjAuNnoiLz4KCTxwYXRoIGZpbGw9IiNmMDAi`+
`IGQ9Im00NjYuNyA1MS42NiAyZS01IC0zNy43Ni0xNjAuMi01LjgzZS00Yy0zNC44MyAwLT`+
`YzLjU0IDI0Ljg4LTYzLjU0IDYwLjkgMCAxOC40NCA3LjAyNiAzNC4yNSAxOC4xNSA0NC43`+
`OSA5Ljk1NCA5LjM2NiAxOS4wMyAxN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`+
`43Nzg4IDE4LjY4IDAuMTYyOSAxMC44Ny0xLjU5MiAxOS42LTUuODkzIDI2LjQyLTEzIDgu`+
`MjQ2LTguNjAxIDEyLjktMjAuMjMgMTMuNDktMzMuNzMgMC40MzY5LTkuOTA0LTEuMzQzLT`+
`E5LjA0LTUuMTY0LTI2LjQ5LTcuMjUzLTE0LjE1LTIyLjMyLTIyLjUyLTQ0LjE5LTI0LjU3`+
`LTQuOTEyLTAuNDU5MS0yMS4xNC0wLjIzMjUtMjUuMzYgMC4zNTQzLTEuNDQ0IDAuMjAwNy`+
`0yLjY5MyAwLjI5NzctMi43NzYgMC4yMTU0LTAuMDgyNi0wLjA4MjQgOS45OTItMTQuOCAy`+
`Mi4zOS0zMi43MSAxMi4zOS0xNy45MSAyMi41NC0zMi42MyAyMi41NC0zMi43MiAwLTAuMD`+
`g1ODYtMjQuMzEtMC4xNTYxLTU0LjA0LTAuMTU2MWgtNTQuNTh6Ii8+Cjwvc3ZnPgo=">`+
`</button>`+
`</a>`;
button.children[0].onclick = () => { console.log(5); };
buttons.appendChild(button);
songs[i].fast = "1";
}
catch (ex) {
//console.error(ex);
}
}
}
}
updateFGH3Links();
console.log(setInterval(updateFGH3Links, 200));
})();
// if refreshing with devcon open, the tab will freeze
@donnaken15
Copy link
Author

@donnaken15
Copy link
Author

@donnaken15
Copy link
Author

script in google apps scripts for transparency
still don't know how this looks to anyone else
https://script.google.com/d/1bBjZs0_LTRGX9L5kE1NdVCLFhuMxltTLfqZuyFvQlPacNwxtDjl-tqga/edit?usp=sharing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment