Created
April 26, 2012 03:12
-
-
Save mohamedmansour/2495416 to your computer and use it in GitHub Desktop.
Bookmarklet for Google+ to auto unignore people
This file contains 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
javascript:(function() { | |
// This is evil. | |
var global = {}; | |
global.unignoredCount = 0; | |
global.IGNORE_DIALOG_SELECTOR = '.Yy.eoTope.b-w.Kz'; | |
global.IGNORE_LINK_SELECTOR = '.k-U-C.k-EoqIId'; | |
global.ACTIONS_DROP_SELECTOR = '.c-wa-Da.b-a.b-a-G.Po4Sz.Vy.c-q-o-a'; | |
global.ACTIONS_IGNORE_SELECTOR = 'div[id=":16"]'; | |
global.LOADING_SELECTOR = '.jb.dp'; | |
global.VALID_URL_NAMESPACE = '^https://plus.google.com/(u/\\d+/)?circles'; | |
global.CONFIRM_TEXT =' \ | |
You have to be in your circles tab for this automation to work. Do you want me \ | |
to redirect you? If you accept, you have to click on the bookmarklet again! \ | |
'; | |
global.START_TEXT = ' \ | |
Please do not touch browser till it finishes automating. \ | |
You can stop at any time by refreshing or closing the browser window. \ | |
'; | |
var initEvent = function(element, str) { | |
var clickEvent = document.createEvent('MouseEvents'); | |
clickEvent.initEvent(str, true, true); | |
element.dispatchEvent(clickEvent); | |
}; | |
var simulateClick = function(element) { | |
initEvent(element, 'mousedown'); | |
initEvent(element, 'click'); | |
initEvent(element, 'mouseup'); | |
}; | |
var prepareBatch = function() { | |
global.container = document.querySelector(global.IGNORE_DIALOG_SELECTOR); | |
global.links = document.querySelectorAll(global.IGNORE_LINK_SELECTOR); | |
global.scrollHeight = global.container.scrollHeight; | |
global.progressBar.setAttribute('max', global.scrollHeight); | |
}; | |
var doUnignoreBatch = function () { | |
global.links = document.querySelectorAll(global.IGNORE_LINK_SELECTOR); | |
if (global.links.length == 0) { | |
global.fixedDiv.parentNode.removeChild(global.fixedDiv); | |
alert('Done unignore process!'); | |
return; | |
} | |
for (var i = 0; i < global.links.length; i++) { | |
global.unignoredCount++; | |
simulateClick(global.links[i]); | |
} | |
global.container.scrollTop += 300; | |
global.progressText.innerText = 'Unignored ' + global.unignoredCount + ' people, still running!'; | |
global.progressBar.setAttribute('value', global.container.scrollTop); | |
if (global.scrollHeight - 500 > 0) { | |
setTimeout(doUnignoreBatch, 1000); | |
} | |
}; | |
var doClickActions = function() { | |
simulateClick(document.querySelector(global.ACTIONS_DROP_SELECTOR)); | |
}; | |
var doClickIgnore = function() { | |
simulateClick(document.querySelector(global.ACTIONS_IGNORE_SELECTOR)); | |
simulateClick(document.querySelector(global.ACTIONS_IGNORE_SELECTOR)); | |
}; | |
var prepareUI = function() { | |
// I hate absolute positioning ... | |
var fixedDiv = document.createElement('div'); | |
fixedDiv.style.position = 'fixed'; | |
fixedDiv.style.top = 0; | |
fixedDiv.style.left = 0; | |
fixedDiv.style.right = 0; | |
fixedDiv.style.height = '120px'; | |
fixedDiv.style.backgroundColor = '#eee'; | |
fixedDiv.style.boxShadow = '0 0 5px 5px #888'; | |
fixedDiv.style.color = '#333'; | |
fixedDiv.style.zIndex = '2000'; | |
global.fixedDiv = fixedDiv; | |
var noticeDiv = document.createElement('span'); | |
noticeDiv.style.width = '500px'; | |
noticeDiv.style.position = 'absolute'; | |
noticeDiv.style.fontSize = '10pt'; | |
noticeDiv.style.top = '2px'; | |
noticeDiv.style.left = 0; | |
noticeDiv.style.right = 0; | |
noticeDiv.style.margin = '0 auto'; | |
noticeDiv.style.textAlign = 'center'; | |
noticeDiv.innerHTML = 'Developed by <a href="https://plus.google.com/116805285176805120365/about">Mohamed Mansour</a>. Auto Unignore All Bookmarklet!'; | |
var progressText = document.createElement('span'); | |
progressText.id = 'progressText'; | |
progressText.style.padding = '10px'; | |
progressText.innerText = 'Starting automation'; | |
progressText.style.width = '500px'; | |
progressText.style.position = 'absolute'; | |
progressText.style.top = '25px'; | |
progressText.style.left = 0; | |
progressText.style.right = 0; | |
progressText.style.fontWeight = 'bold'; | |
progressText.style.textAlign = 'center'; | |
progressText.style.lineHeight = '30px'; | |
progressText.style.margin = '0 auto'; | |
global.progressText = progressText; | |
var progressBar = document.createElement('progress'); | |
progressBar.id = 'progressBar'; | |
progressBar.style.padding = '10px'; | |
progressBar.style.margin = '0 auto'; | |
progressBar.style.display = 'block'; | |
progressBar.style.height = '50px'; | |
progressBar.style.width = '500px'; | |
progressBar.style.position = 'absolute'; | |
progressBar.style.top = '25px'; | |
progressBar.style.left = 0; | |
progressBar.style.right = 0; | |
global.progressBar = progressBar; | |
var charityDiv = document.createElement('span'); | |
charityDiv.style.width = '600px'; | |
charityDiv.style.position = 'absolute'; | |
charityDiv.style.fontSize = '10pt'; | |
charityDiv.style.top = '80px'; | |
charityDiv.style.left = 0; | |
charityDiv.style.right = 0; | |
charityDiv.style.margin = '0 auto'; | |
charityDiv.style.textAlign = 'center'; | |
charityDiv.innerHTML = 'If you enjoy my open source work and want to support its development, please consider making a donation to <a href="http://www.crowdrise.com/code-for-charity" target="_blank">code for charity</a> on crowdrise!'; | |
fixedDiv.appendChild(noticeDiv); | |
fixedDiv.appendChild(progressBar); | |
fixedDiv.appendChild(progressText); | |
fixedDiv.appendChild(charityDiv); | |
document.body.appendChild(fixedDiv); | |
}; | |
var process = function() { | |
var fncall = global.callbackStack.shift(); | |
if (fncall) { | |
var fn = fncall[0]; | |
var timeout = fncall[1]; | |
var status = fncall[2]; | |
global.progressText.innerText = status; | |
fn(); | |
setTimeout(process, timeout); | |
} | |
else { | |
console.log('Done!'); | |
} | |
}; | |
var start = function() { | |
if (!document.location.href.match(global.VALID_URL_NAMESPACE)) { | |
if (confirm(global.CONFIRM_TEXT)) { | |
window.location.href = 'https://plus.google.com/circles'; | |
} | |
else { | |
alert(global.START_TEXT); | |
} | |
return; | |
} | |
// Prepare progress UI. | |
prepareUI(); | |
// Reset the ignoreCount in case we are running it again. | |
global.unignoredCount = 0; | |
// Call function stack, inorder process 1 sec between. | |
global.callbackStack = []; | |
if (!document.querySelector(global.IGNORE_DIALOG_SELECTOR)) { | |
global.callbackStack.push([doClickActions, 1000, 'Preparing dialog']); | |
global.callbackStack.push([doClickIgnore, 10000, 'Preparing dialog']); | |
} | |
global.callbackStack.push([prepareBatch, 2000, 'Populating batch']); | |
global.callbackStack.push([doUnignoreBatch, 1000, 'Starting unignore process']); | |
process(); | |
}; | |
// Lets start the automation. | |
start(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment