Skip to content

Instantly share code, notes, and snippets.

@Pash237
Last active April 2, 2018 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pash237/9c8ac7095c6b38b2a57f855dde33eb09 to your computer and use it in GitHub Desktop.
Save Pash237/9c8ac7095c6b38b2a57f855dde33eb09 to your computer and use it in GitHub Desktop.
Remove Nikon SnapBridge photos from Google Photos (NOT RELIABLE!)
function elementWithClassName(className, query) {
var elements = document.getElementsByClassName(className);
//search for visible elements first
for (i=0; i<elements.length; i++) {
var element = elements[i];
if (query != undefined && element.outerHTML.indexOf(query) == -1) continue;
if (!isVisible(element)) continue;
return element;
}
//now search for all
for (i=0; i<elements.length; i++) {
var element = elements[i];
if (query != undefined && element.outerHTML.indexOf(query) == -1) continue;
return element;
}
return null;
}
function showNextPhoto() {
elementWithClassName("oJhm5 gMFQN eLNT1d", "View next photo").click();
setTimeout(function() {
console.log("showing " + filename() + ", " + dimensions().width + "x" + dimensions().height);
}, 500);
}
function filename() {
return elementWithClassName("R9U8ab", "Filename").textContent;
}
function dimensions() {
var innerHTML = elementWithClassName("oBMhZb", "Size:").innerHTML;
return {
"width": /(\d+)\s+×\s+(\d+)/g.exec(innerHTML)[1],
"height": /(\d+)\s+×\s+(\d+)/g.exec(innerHTML)[2]
};
}
function cameraModel() {
return elementWithClassName("R9U8ab", "Camera model").textContent;
}
function deleteCurrentPhoto() {
console.log("Deleting " + filename() + ", " + dimensions().width + "x" + dimensions().height + "...");
elementWithClassName("mUbCce p9Nwte cx6Jyd", "Delete").click()
setTimeout(function() {
elementWithClassName("O0WRkf oG5Srb HQ8yf C0oVfc kHssdc HvOprf").click();
}, 500);
}
function shouldDeleteCurrentPhoto() {
if (cameraModel().indexOf("NIKON") == -1) {
return false;
}
var width = dimensions().width;
var height = dimensions().height;
if ((width == 1620 && height == 1080) || (width == 1080 && height == 1620)) {
return true;
}
return false;
}
function isVisible(elem) {
if (!(elem instanceof Element)) throw Error('DomUtil: elem is not an element.');
const style = getComputedStyle(elem);
if (style.display === 'none') return false;
if (style.visibility !== 'visible') return false;
if (style.opacity < 0.1) return false;
if (elem.offsetWidth + elem.offsetHeight + elem.getBoundingClientRect().height +
elem.getBoundingClientRect().width === 0) {
return false;
}
const elemCenter = {
x: elem.getBoundingClientRect().left + elem.offsetWidth / 2,
y: elem.getBoundingClientRect().top + elem.offsetHeight / 2
};
if (elemCenter.x < 0) return false;
if (elemCenter.x > (document.documentElement.clientWidth || window.innerWidth)) return false;
if (elemCenter.y < 0) return false;
if (elemCenter.y > (document.documentElement.clientHeight || window.innerHeight)) return false;
let pointContainer = document.elementFromPoint(elemCenter.x, elemCenter.y);
do {
if (pointContainer === elem) return true;
} while (pointContainer = pointContainer.parentNode);
return false;
}
function loop() {
if (shouldDeleteCurrentPhoto()) {
deleteCurrentPhoto();
}
setTimeout(showNextPhoto, 1000);
setTimeout(loop, 2000);
}
loop();
@Pash237
Copy link
Author

Pash237 commented Apr 2, 2018

This DOM-based script is not reliable at all — new node.js version is there: https://gist.github.com/Pash237/e08712b7faa8e32519e7677d8a81e2bc

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