Last active
August 25, 2021 22:08
-
-
Save TeeeeLS/82ade3d2ab699c3ce7f78c5edbf7a626 to your computer and use it in GitHub Desktop.
Literally just a tweak from https://gist.github.com/prehensile/ce9f60e1aa75fe4bc22e1b61afbcdc02
This file contains hidden or 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 Generate Parentzone Gallery image links | |
// @namespace http://tampermonkey.net/ | |
// @version 0.2 | |
// @description Adds a list of links to all of the images in a ParentZone gallery to the page itself. | |
// @author @prehensile | |
// @match https://www.parentzone.me/gallery | |
// @grant none | |
// ==/UserScript== | |
var __pzKey = "key"; | |
// generate links in page from gallery data | |
function parseData( dat ){ | |
const linkList = document.createElement("ul"); | |
for( const item of dat ){ | |
var itemId = item["id"]; | |
const url = "https://api.iconnectdaily.net/api/v1/media/" + itemId + "?key=" + __pzKey + "&size=full"; | |
//console.log( url ); | |
const listItem = document.createElement("li"); | |
const hrefTag = document.createElement("a"); | |
hrefTag.classList.add("generatedLink"); | |
hrefTag.href = url; | |
hrefTag.innerHTML = item["fileName"]; | |
listItem.appendChild( hrefTag ); | |
linkList.appendChild( listItem ); | |
} | |
//console.log( linkList); | |
document.body.insertBefore( linkList, document.body.firstChild); | |
} | |
// intercept gallery data from API call | |
(function(open) { | |
XMLHttpRequest.prototype.open = function() { | |
if( arguments[1] == "https://api.parentzone.me/v1/gallery/" ){ | |
this.addEventListener("readystatechange", function() { | |
if( this.readyState == 4 ) { | |
var status = this.status; | |
if(status >= 200 && status < 400){ | |
// console.log( this.response ); | |
parseData( this.response ); | |
} | |
} | |
}, false); | |
} | |
open.apply(this, arguments); | |
}; | |
})(XMLHttpRequest.prototype.open); | |
// intercept the parentzone API key from XMLHttpRequest.setRequestHeader() calls | |
(function(setRequestHeader) { | |
XMLHttpRequest.prototype.setRequestHeader = function() { | |
console.log( arguments ); | |
if( arguments[0] == "X-API-Key" ){ | |
__pzKey = arguments[1]; | |
} | |
setRequestHeader.apply(this, arguments); | |
}; | |
})(XMLHttpRequest.prototype.setRequestHeader); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment