Skip to content

Instantly share code, notes, and snippets.

@bfosterscripps
Last active August 29, 2015 14:26
Show Gist options
  • Save bfosterscripps/b4f573e2d7d275c2301e to your computer and use it in GitHub Desktop.
Save bfosterscripps/b4f573e2d7d275c2301e to your computer and use it in GitHub Desktop.
Bookmarklet to get unique CQ image paths to develop filters for package dependencies.
(function(){
function createTextarea(){
var output = document.createElement('textarea'),
yOffset = window.pageYOffset + 100;
document.body.appendChild(output);
output.style.zIndex = 9999;
output.style.width = '550px';
output.style.height = '300px';
output.style.position = 'absolute';
output.style.background = 'white';
output.style.left = '100px';
output.style.top = yOffset + 'px';
output.setAttribute('class', 'bookmarklet-query-results');
return output;
}
var els = document.getElementsByTagName('img');
paths = [],
currentValue = '',
output = '',
isUnique = true;
[].forEach.call(els, function(el){
isUnique = true;
// get the value of the src or input val
if(typeof el.value !== 'undefined'){
currentValue = el.value;
}else if(typeof el.src !== 'undefined'){
currentValue = el.src;
}
// add to array if unique and is content path
if(/\/content\//.test(currentValue)){
// just get the part from /content/... on
currentValue = /(\/content\/.*?)$/.exec(currentValue)[0];
//console.log('content, on: ' + currentValue);
// kill the .rend...jpeg at the end of the string
currentValue = (/(\/content\/.*?)\.rend/.test(currentValue)) ? /(\/content\/.*?)\.rend/.exec(currentValue)[1] : currentValue;
//console.log('minus rendition: ' + currentValue);
for(var i = 0; i < paths.length; i++){
if(paths[i] == currentValue){
isUnique = false;
}
}
if(isUnique){
paths.push(currentValue);
}
}
});
for(var i = 0; i < paths.length; i++){
output += (paths[i] + '\n');
}
var textArea = createTextarea();
// fill the text area with the paths
textArea.innerHTML = output;
// disappear the text area
setTimeout(function(){
document.body.removeChild(textArea);
}, 3500);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment