Skip to content

Instantly share code, notes, and snippets.

Avatar

Alan Richardson eviltester

View GitHub Profile
@eviltester
eviltester / gist:7d8dc6e3665e038772ea8be1e5c3af98
Created Sep 1, 2021
Automatically Create a Markdown TOC for current page
View gist:7d8dc6e3665e038772ea8be1e5c3af98
var output="";
document.querySelectorAll("h2,h3,h4,h5").forEach((element) => {
var headingNum = element.tagName.toLowerCase().replace('h','');
var indent = (parseInt(headingNum)-2)*3;
var spaces= indent>0 ? Array(indent).fill(' ').join('') : '';
var href= element.id ? element.id : element.innerText.toLowerCase().replaceAll(" ","-")
output+=spaces + "- [" + element.innerText +"](#" + href + ")\n" })
console.log(output);
@eviltester
eviltester / gist:ac7ed61c589855c7d35fe56e6718cc77
Created Sep 1, 2021
Calculate average number of views for a YouTube channel's visible videos
View gist:ac7ed61c589855c7d35fe56e6718cc77
const viewCounts = [...document.querySelectorAll('div#metadata-line span:first-child')].map((node) => {viewCount = node.innerText.replace(" views","");valueOfViewCount = viewCount.indexOf("K")==-1 ? parseInt(viewCount,10) : parseFloat(viewCount)*1000; return valueOfViewCount;});
console.log(viewCounts);
const sum = viewCounts.reduce(( previousValue, currentValue ) => previousValue + currentValue);
console.log(`${sum} / ${viewCounts.length}`);
console.log(sum/viewCounts.length)
@eviltester
eviltester / closeAllDoors.js
Last active Jan 5, 2021
Challenge 13 of the 12 Days of TestMas 2020 challenge
View closeAllDoors.js
var _0x2014=['class','div.door','27DvQMlz','323835EbRkHy','236136uYgZaz','data-date','2022/12/12','removeAttribute','988067lbpwFN','181827nlOrMb','785308bizyhW','querySelectorAll','1DhEcvB','div.door\x20a','forEach','setAttribute','1010029ZNxBZi','13133dzTUde'];var _0x29e1=function(_0x2c1487,_0x3e2de6){_0x2c1487=_0x2c1487-0x10b;var _0x20149e=_0x2014[_0x2c1487];return _0x20149e;};var _0x3b985f=_0x29e1;(function(_0xe08d5a,_0x2ed766){var _0x5a9c86=_0x29e1;while(!![]){try{var _0x208977=-parseInt(_0x5a9c86(0x112))*parseInt(_0x5a9c86(0x11b))+parseInt(_0x5a9c86(0x118))+parseInt(_0x5a9c86(0x117))+parseInt(_0x5a9c86(0x119))+parseInt(_0x5a9c86(0x113))+parseInt(_0x5a9c86(0x111))*-parseInt(_0x5a9c86(0x10e))+-parseInt(_0x5a9c86(0x10d));if(_0x208977===_0x2ed766)break;else _0xe08d5a['push'](_0xe08d5a['shift']());}catch(_0x10ce15){_0xe08d5a['push'](_0xe08d5a['shift']());}}}(_0x2014,0x7ac63),document[_0x3b985f(0x11a)](_0x3b985f(0x110))[_0x3b985f(0x10b)](_0x10bccc=>{var _0x1412a1=_0x3b985f;_0x10bccc[_0x1412a1(0x10c)](_0x1412a1
@eviltester
eviltester / gist:5fb355076c11c9eed8ef0a56a96971f7
Created Jun 23, 2020
some example page scraping examples and output to console using JavaScript
View gist:5fb355076c11c9eed8ef0a56a96971f7
document.querySelectorAll("tbody tr td[style*='15px']").forEach(function(item, index){console.log(item.innerText)})
document.querySelectorAll("tbody tr td[style*='15px']").forEach(function(item, index){console.log("<option value='" + item.innerText + "'>" + item.innerText + "</option>")})
document.querySelectorAll("tbody tr td[style*='15px']").forEach(function(item, index){console.log("\"" + item.innerText + "\", ")})
@eviltester
eviltester / format web pages for readability
Created Jun 16, 2020
right click, inspect, find <body>, paste this into the element style
View format web pages for readability
color: black !important;
background: white !important;
font-size: 2em !important;
font-family: sans-serif !important;
View gist:71c05ae1ea584826feac7e140f249576
// find the text line in a feed item e.g. [person] commented on this
window.setInterval(function(){
Array.from(document.querySelectorAll("div.feed-shared-text-view > span > span")).forEach(function(item){
if(item.innerText.endsWith(" this") || item.innerText.endsWith(" this insightful")){
// mark it for ignoring and the parent for deletion
item.className="IGNORE";
item.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.style.display="none";
item.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.className="DELETEENTRY";
}});},100)
View gist:42de6e41d2d1cdd591be0fc024f10920
// https://playtictactoe.org/
function playGame(){
var restart = document.querySelector("div.restart");
if(restart.style.display=="block"){
restart.click()
}else{
var squares = document.querySelectorAll("div.square > div:not(.x):not(.o)");
var item=Math.floor(Math.random()*squares.length)
View gist:cb27abecdd2eda4abbe82e68ddbd32f7
// http://zzzscore.com/1to50/en
function clickAllSquares(){
var clickedCount=0;
for(currentNum=1;currentNum<51;currentNum++){
console.log("processing "+currentNum);
cells = document.querySelectorAll("div#grid div");
for(var cellindex=0;cellindex<cells.length;cellindex++){
var foundInt = parseInt(cells[cellindex].innerText);
if(foundInt==currentNum){
View gist:f4658a75f99947ecf140cfa1b2ebc369
// http://zzzscore.com/1to50/en
function clickAllSquares(){
var clickedCount=0;
for(currentNum=1;currentNum<51;currentNum++){
console.log("processing "+currentNum);
cells = document.querySelectorAll("div#grid div");
for(var cellindex=0;cellindex<cells.length;cellindex++){
var foundInt = parseInt(cells[cellindex].innerText);
if(foundInt==currentNum){
View bitbloxs examples
var xhttp = new XMLHttpRequest();
xhttp.open("GET","https://bitbloxs.herokuapp.com/boxes?api_key=thisistheapikey");
xhttp.onload = (e)=>{
console.log(xhttp.status);
console.log(xhttp.responseText);
}
xhttp.send(null);