Skip to content

Instantly share code, notes, and snippets.

@DamonOehlman
Last active July 30, 2021 01:34
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DamonOehlman/68db82c8286003063d6d to your computer and use it in GitHub Desktop.
Save DamonOehlman/68db82c8286003063d6d to your computer and use it in GitHub Desktop.
Interesting webpage injection scripts

Youtube -> Imgur Screenshot Helper (copy and paste into your browser console when on a video site)

var clientId = ''; // insert your imgur application client id here
var videos = document.getElementsByTagName('video'), canvas = document.createElement('canvas'), context = canvas.getContext('2d'), http = new XMLHttpRequest();
canvas.width = videos[0].videoWidth; canvas.height = videos[0].videoHeight;
context.drawImage(videos[0], 0, 0);

var data = JSON.stringify({
  image: canvas.toDataURL('image/jpeg', 0.9).split(',')[1]
});

//Send the proper header information along with the request
http.open('POST', 'https://api.imgur.com/3/image', true);
http.setRequestHeader('Content-type','application/json; charset=utf-8');
// http.setRequestHeader('Content-length', data.length);
http.setRequestHeader('Authorization', 'Client-ID ' + clientId);
// http.setRequestHeader('Connection', "close");

http.onreadystatechange = function() {//Call a function when the state changes.
    if(http.readyState == 4 && http.status == 200) {
       try {
          console.log(JSON.parse(http.responseText).data.link);
       }
       catch (e) {
       }
    }
}

http.send(data);

Get a the base64 image/jpeg data for an image that you've inspected from a site. Need to make sure that the image has been served from the same domain as the page. Basically, inspect the element and then copy and paste this code into devtools console in chrome.

var canvas = document.createElement('canvas');
var maxCharsPerLine = 74;

canvas.width = $0.width;
canvas.height = $0.height;

var context = canvas.getContext('2d');
context.drawImage($0, 0, 0);

var dataURL = canvas.toDataURL('image/jpeg', 0.8);
var lines = [];

while (dataURL.length > maxCharsPerLine) {
  lines.push(dataURL.slice(0, maxCharsPerLine));
  dataURL = dataURL.slice(maxCharsPerLine);
}

if (dataURL.length > 0) {
  lines.push(dataURL);
}

copy('module.exports = [\n\t\'' + lines.join('\',\n\t\'') + '\'\n].join(\'\');');
console.log('testImage variable string copied to the clipboard');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment