Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate ShareMeNot functionality #196

Merged
merged 14 commits into from
Jun 10, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed AddThis button re-enabling.
  • Loading branch information
froeschele committed Jun 7, 2014
commit b857e863354d96085087af79165eecba9b6a11e2
31 changes: 27 additions & 4 deletions src/socialwidgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function createReplacementButtonImage(tracker) {
// once when the user clicks on a replacement button
// (it executes for the buttons that have been previously
// clicked as well)
replaceButtonWithIframeAndUnblockTracker(button, details, iframeUrl);
replaceButtonWithIframeAndUnblockTracker(button, buttonData.unblockDomains, iframeUrl);
});
break;

Expand All @@ -117,7 +117,7 @@ function createReplacementButtonImage(tracker) {
// once when the user clicks on a replacement button
// (it executes for the buttons that have been previously
// clicked as well)
replaceButtonWithHtmlCodeAndUnblockTracker(button, details, details);
replaceButtonWithHtmlCodeAndUnblockTracker(button, buttonData.unblockDomains, details);
});
break;

Expand Down Expand Up @@ -204,12 +204,35 @@ function replaceButtonWithHtmlCodeAndUnblockTracker(button, tracker, html) {
codeContainer.innerHTML = html;

button.parentNode.replaceChild(codeContainer, button);

replaceScriptsRecurse(codeContainer);

button.removeEventListener("click");
}
});
}

/**
* Dumping scripts into innerHTML won't execute them, so replace them
* with executable scripts.
*/
function replaceScriptsRecurse(node) {
if (node.getAttribute && node.getAttribute("type") == "text/javascript") {
var script = document.createElement("script");
script.text = node.innerHTML;
script.src = node.src;
node.parentNode.replaceChild(script, node);
} else {
var i = 0;
var children = node.childNodes;
while ( i < children.length) {
replaceScriptsRecurse(children[i]);
i++;
}
}
return node;
}

/**
* Replaces all tracker buttons on the current web page with the internal
* replacement buttons, respecting the user's blocking settings.
Expand Down Expand Up @@ -269,10 +292,10 @@ function getTrackerData(callback) {
* @param {Function} callback the function to call after the tracker has
* been unblocked
*/
function unblockTracker(buttonUrl, callback) {
function unblockTracker(buttonUrls, callback) {
var request = {
"unblockSocialWidget" : true,
"buttonUrl": buttonUrl
"buttonUrls": buttonUrls
};
chrome.runtime.sendMessage(request, callback);
}
Expand Down
25 changes: 25 additions & 0 deletions src/socialwidgets.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
],
"replacementButton": {
"details": "\u003C\u0021\u002D\u002D\u0020\u0041\u0064\u0064\u0054\u0068\u0069\u0073\u0020\u0042\u0075\u0074\u0074\u006F\u006E\u0020\u0042\u0045\u0047\u0049\u004E\u0020\u002D\u002D\u003E\u000A\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003C\u0064\u0069\u0076\u0020\u0063\u006C\u0061\u0073\u0073\u003D\u0022\u0061\u0064\u0064\u0074\u0068\u0069\u0073\u005F\u0074\u006F\u006F\u006C\u0062\u006F\u0078\u0020\u0061\u0064\u0064\u0074\u0068\u0069\u0073\u005F\u0064\u0065\u0066\u0061\u0075\u006C\u0074\u005F\u0073\u0074\u0079\u006C\u0065\u0020\u0061\u0064\u0064\u0074\u0068\u0069\u0073\u005F\u0033\u0032\u0078\u0033\u0032\u005F\u0073\u0074\u0079\u006C\u0065\u0022\u003E\u000A\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003C\u0061\u0020\u0063\u006C\u0061\u0073\u0073\u003D\u0022\u0061\u0064\u0064\u0074\u0068\u0069\u0073\u005F\u0062\u0075\u0074\u0074\u006F\u006E\u005F\u0070\u0072\u0065\u0066\u0065\u0072\u0072\u0065\u0064\u005F\u0031\u0022\u003E\u003C\u002F\u0061\u003E\u000A\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003C\u0061\u0020\u0063\u006C\u0061\u0073\u0073\u003D\u0022\u0061\u0064\u0064\u0074\u0068\u0069\u0073\u005F\u0062\u0075\u0074\u0074\u006F\u006E\u005F\u0070\u0072\u0065\u0066\u0065\u0072\u0072\u0065\u0064\u005F\u0032\u0022\u003E\u003C\u002F\u0061\u003E\u000A\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003C\u0061\u0020\u0063\u006C\u0061\u0073\u0073\u003D\u0022\u0061\u0064\u0064\u0074\u0068\u0069\u0073\u005F\u0062\u0075\u0074\u0074\u006F\u006E\u005F\u0070\u0072\u0065\u0066\u0065\u0072\u0072\u0065\u0064\u005F\u0033\u0022\u003E\u003C\u002F\u0061\u003E\u000A\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003C\u0061\u0020\u0063\u006C\u0061\u0073\u0073\u003D\u0022\u0061\u0064\u0064\u0074\u0068\u0069\u0073\u005F\u0062\u0075\u0074\u0074\u006F\u006E\u005F\u0070\u0072\u0065\u0066\u0065\u0072\u0072\u0065\u0064\u005F\u0034\u0022\u003E\u003C\u002F\u0061\u003E\u000A\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003C\u0061\u0020\u0063\u006C\u0061\u0073\u0073\u003D\u0022\u0061\u0064\u0064\u0074\u0068\u0069\u0073\u005F\u0062\u0075\u0074\u0074\u006F\u006E\u005F\u0063\u006F\u006D\u0070\u0061\u0063\u0074\u0022\u003E\u003C\u002F\u0061\u003E\u000A\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003C\u0061\u0020\u0063\u006C\u0061\u0073\u0073\u003D\u0022\u0061\u0064\u0064\u0074\u0068\u0069\u0073\u005F\u0063\u006F\u0075\u006E\u0074\u0065\u0072\u0020\u0061\u0064\u0064\u0074\u0068\u0069\u0073\u005F\u0062\u0075\u0062\u0062\u006C\u0065\u005F\u0073\u0074\u0079\u006C\u0065\u0022\u003E\u003C\u002F\u0061\u003E\u000A\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003C\u002F\u0064\u0069\u0076\u003E\u000A\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003C\u0073\u0063\u0072\u0069\u0070\u0074\u0020\u0074\u0079\u0070\u0065\u003D\u0022\u0074\u0065\u0078\u0074\u002F\u006A\u0061\u0076\u0061\u0073\u0063\u0072\u0069\u0070\u0074\u0022\u003E\u0076\u0061\u0072\u0020\u0061\u0064\u0064\u0074\u0068\u0069\u0073\u005F\u0063\u006F\u006E\u0066\u0069\u0067\u0020\u003D\u0020\u007B\u0022\u0064\u0061\u0074\u0061\u005F\u0074\u0072\u0061\u0063\u006B\u005F\u0061\u0064\u0064\u0072\u0065\u0073\u0073\u0062\u0061\u0072\u0022\u003A\u0074\u0072\u0075\u0065\u007D\u003B\u003C\u002F\u0073\u0063\u0072\u0069\u0070\u0074\u003E\u000A\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003C\u0073\u0063\u0072\u0069\u0070\u0074\u0020\u0074\u0079\u0070\u0065\u003D\u0022\u0074\u0065\u0078\u0074\u002F\u006A\u0061\u0076\u0061\u0073\u0063\u0072\u0069\u0070\u0074\u0022\u0020\u0073\u0072\u0063\u003D\u0022\u002F\u002F\u0073\u0037\u002E\u0061\u0064\u0064\u0074\u0068\u0069\u0073\u002E\u0063\u006F\u006D\u002F\u006A\u0073\u002F\u0033\u0030\u0030\u002F\u0061\u0064\u0064\u0074\u0068\u0069\u0073\u005F\u0077\u0069\u0064\u0067\u0065\u0074\u002E\u006A\u0073\u0023\u0070\u0075\u0062\u0069\u0064\u003D\u0072\u0061\u002D\u0035\u0032\u0032\u0064\u0036\u0030\u0030\u0064\u0033\u0062\u0035\u0033\u0035\u0065\u0062\u0066\u0022\u003E\u003C\u002F\u0073\u0063\u0072\u0069\u0070\u0074\u003E\u000A\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003C\u0021\u002D\u002D\u0020\u0041\u0064\u0064\u0054\u0068\u0069\u0073\u0020\u0042\u0075\u0074\u0074\u006F\u006E\u0020\u0045\u004E\u0044\u0020\u002D\u002D\u003E",
"unblockDomains": [
"s7.addthis.com",
"ct1.addthis.com"
],
"imagePath": "AddThis.svg",
"type": 2
}
Expand All @@ -27,6 +31,9 @@
],
"replacementButton": {
"details": "http://www.digg.com/submit?url=",
"unblockDomains": [
"http://www.digg.com/submit?url="
],
"imagePath": "Digg.svg",
"type": 0
}
Expand All @@ -49,6 +56,9 @@
],
"replacementButton": {
"details": "https://www.facebook.com/plugins/like.php?href=",
"unblockDomains": [
"https://www.facebook.com/plugins/like.php?href="
],
"imagePath": "Facebook.svg",
"type": 1
}
Expand All @@ -68,6 +78,9 @@
],
"replacementButton": {
"details": "https://plusone.google.com/_/+1/fastbutton?url=",
"unblockDomains": [
"https://plusone.google.com/_/+1/fastbutton?url="
],
"imagePath": "Google Plus.svg",
"type": 1
}
Expand All @@ -85,6 +98,9 @@
],
"replacementButton": {
"details": "http://www.linkedin.com/shareArticle?mini=true&url=",
"unblockDomains": [
"http://www.linkedin.com/shareArticle?mini=true&url="
],
"imagePath": "LinkedIn.svg",
"type": 0
}
Expand All @@ -104,6 +120,9 @@
],
"replacementButton": {
"details": "http://pinterest.com/pin/create/button/?url=",
"unblockDomains": [
"http://pinterest.com/pin/create/button/?url="
],
"imagePath": "Pinterest.svg",
"type": 0
}
Expand All @@ -123,6 +142,9 @@
],
"replacementButton": {
"details": "http://www.stumbleupon.com/badge/?url=",
"unblockDomains": [
"http://www.stumbleupon.com/badge/?url="
],
"imagePath": "StumbleUpon.svg",
"type": 0
}
Expand All @@ -141,6 +163,9 @@
],
"replacementButton": {
"details": "https://twitter.com/intent/tweet?url=",
"unblockDomains": [
"https://twitter.com/intent/tweet?url="
],
"imagePath": "Twitter.svg",
"type": 0
}
Expand Down
16 changes: 9 additions & 7 deletions src/webrequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ function getSocialWidgetBlockList(tabId) {

// Check if tab is temporarily unblocked for tracker
function isSocialWidgetTemporaryUnblock(tabId, url, frameId) {
console.log("checking...");
var exceptions = temporarySocialWidgetUnblock[tabId];
if (exceptions == undefined) {
return false;
Expand All @@ -322,19 +321,22 @@ function isSocialWidgetTemporaryUnblock(tabId, url, frameId) {
var frameHost = extractHostFromURL(getFrameUrl(tabId, frameId));
var frameExcept = (exceptions.indexOf(frameHost) != -1);

console.log((requestExcept || frameExcept) + " : exception for " + url);
//console.log((requestExcept || frameExcept) + " : exception for " + url);

return (requestExcept || frameExcept);
}

// Unblocks a tracker just temporarily on this tab, because the user has clicked the
// corresponding replacement social widget.
function unblockSocialWidgetOnTab(tabId, socialWidgetUrl) {
function unblockSocialWidgetOnTab(tabId, socialWidgetUrls) {
if (temporarySocialWidgetUnblock[tabId] == undefined){
temporarySocialWidgetUnblock[tabId] = [];
}
var socialWidgetHost = extractHostFromURL(socialWidgetUrl);
temporarySocialWidgetUnblock[tabId].push(socialWidgetHost);
for (var i in socialWidgetUrls) {
var socialWidgetUrl = socialWidgetUrls[i];
var socialWidgetHost = extractHostFromURL(socialWidgetUrl);
temporarySocialWidgetUnblock[tabId].push(socialWidgetHost);
}
}

chrome.runtime.onMessage.addListener(
Expand All @@ -352,8 +354,8 @@ chrome.runtime.onMessage.addListener(
sendResponse(socialWidgetBlockList);
}
if(request.unblockSocialWidget){
var socialWidgetUrl = request.buttonUrl;
unblockSocialWidgetOnTab(sender.tab.id, socialWidgetUrl);
var socialWidgetUrls = request.buttonUrls;
unblockSocialWidgetOnTab(sender.tab.id, socialWidgetUrls);
sendResponse();
}
}
Expand Down