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
Next Next commit
Beginning integration of ShareMeNot: added resources, useless callback.
  • Loading branch information
froeschele committed May 31, 2014
commit cc3347f7c9bcc62ab10141611d26e27793f49716
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ buildtools/jshydra/mozilla/js

#zip files
*.zip

#Mac DS_Store
*.DS_Store
4 changes: 3 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@
"src/blockedDomainList.js",
"src/webrequest.js",
"src/heuristicblocking.js",
"src/socialwidgetloader.js",
"src/background.js"
]
},
"content_scripts": [
{
"js": [
"src/include.preload.js",
"src/clobbercookie.js"
"src/clobbercookie.js",
"src/socialwidgets.js"
],
"matches": [
"<all_urls>"
Expand Down
38 changes: 38 additions & 0 deletions skin/socialwidgets.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
ShareMeNot is licensed under the MIT license:
http://www.opensource.org/licenses/mit-license.php


Copyright (c) 2012 University of Washington

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

.sharemenotReplacementButton {
border: none !important;
cursor: pointer !important;
height: auto !important;
width: auto !important;
}

.sharemenotOriginalButton {
border: none !important;
height: 1.5em !important;
}
139 changes: 139 additions & 0 deletions skin/socialwidgets/Digg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 105 additions & 0 deletions skin/socialwidgets/Facebook.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 105 additions & 0 deletions skin/socialwidgets/Google Plus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
128 changes: 128 additions & 0 deletions skin/socialwidgets/LinkedIn.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
128 changes: 128 additions & 0 deletions skin/socialwidgets/Pinterest.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
117 changes: 117 additions & 0 deletions skin/socialwidgets/StumbleUpon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
128 changes: 128 additions & 0 deletions skin/socialwidgets/Twitter.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
147 changes: 147 additions & 0 deletions socialwidgets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
{
"AddThis": {
"domain": "addthis.com",
"matchPatterns": [
"*://*.addthis.com/js/250/addthis_widget.js*"
],

"buttonSelectors": [
".addthis_toolbox"
],
"replacementButton": {
"details": "\u003c!-- AddThis Button BEGIN --\u003e\r\n\u003cdiv class=\\\"addthis_toolbox addthis_default_style \\\"\u003e\r\n\u003ca class=\\\"addthis_button_facebook_like\\\" fb:like:layout=\\\"button_count\\\"\u003e\u003c/a\u003e\r\n\u003ca class=\\\"addthis_button_tweet\\\"\u003e\u003c/a\u003e\r\n\u003ca class=\\\"addthis_button_google_plusone\\\" g:plusone:size=\\\"medium\\\"\u003e\u003c/a\u003e\r\n\u003ca class=\\\"addthis_counter addthis_pill_style\\\"\u003e\u003c/a\u003e\r\n\u003c/div\u003e\r\n\u003cscript type=\\\"text/javascript\\\" src=\\\"http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4fdfd3a1133d9ee1\\\"\u003e\u003c/script\u003e\r\n\u003c!-- AddThis Button END --\u003e",
"imagePath": "AddThis.svg",
"type": 2
}
},

"Digg": {
"domain": "digg.com",
"matchPatterns": [
"*://*.widgets.digg.com/buttons.js*",
"*://*.widgets.digg.com/*"
],

"buttonSelectors": [
".DiggThisButton"
],
"replacementButton": {
"details": "http://www.digg.com/submit?url=*",
"imagePath": "Digg.svg",
"type": 0
}
},

"Facebook": {
"domain": "facebook.com",
"matchPatterns": [
"*://*.connect.facebook.net/*",
"*://*.facebook.com/plugins/like.php*",
"*://*.facebook.com/plugins/likebox.php*",
"*://*.facebook.com/plugins/activity.php*",
"*://*.ak.facebook.com/connect*",
"*://*.facebook.com/dialog/oauth*"
],

"buttonSelectors": [
"fb\\:like",
"iframe[src*='://www.facebook.com/plugins/like.php']"
],
"replacementButton": {
"details": "https://www.facebook.com/plugins/like.php?href=",
"imagePath": "Facebook.svg",
"type": 1
}
},

"Google+": {
"domain": "google.com",
"matchPatterns": [
"*://*.apis.google.com/js/plusone.js*",
"*://*.plusone.google.com/_/+1/fastbutton*",
"*://*.plusone.google.com/_/apps-static*",
"*://*.apis.google.com/_/apps-static*"
],

"buttonSelectors": [
"g\\:plusone"
],
"replacementButton": {
"details": "https://plusone.google.com/_/+1/fastbutton?url=",
"imagePath": "Google Plus.svg",
"type": 1
}
},

"LinkedIn": {
"domain": "linkedin.com",
"matchPatterns": [
"*://*.platform.linkedin.com/*",
"*://*.linkedin.com/analytics/*"
],

"buttonSelectors": [
"script[type='in/share']"
],
"replacementButton": {
"details": "http://www.linkedin.com/shareArticle?mini=true&url=",
"imagePath": "LinkedIn.svg",
"type": 0
}
},

"Pinterest": {
"domain": "pinterest.com",
"matchPatterns": [
"*://*.assets.pinterest.com/js/pinit.js*",
"*://*.assets.pinterest.com/imagePaths/PinExt.png*",
"*://*.passets-cdn.pinterest.com/imagePaths/about/buttons/*"
],

"buttonSelectors": [
".pin-it-button"
],
"replacementButton": {
"details": "http://pinterest.com/pin/create/button/?url=",
"imagePath": "Pinterest.svg",
"type": 0
}
},

"StumbleUpon": {
"domain": "stumbleupon.com",
"matchPatterns": [
"*://*.platform.stumbleupon.com/1/widgets.js*",
"*://*.stumbleupon.com/hostedbadge.php*",
"*://*.badge.stumbleupon.com/*"
],

"buttonSelectors": [
"su\\:badge",
"script[src^='http://www.stumbleupon.com/hostedbadge.php']"
],
"replacementButton": {
"details": "http://www.stumbleupon.com/badge/?url=",
"imagePath": "StumbleUpon.svg",
"type": 0
}
},

"Twitter": {
"domain": "twitter.com",
"matchPatterns": [
"*://*.platform.twitter.com/widgets.js*",
"*://*.platform.twitter.com/*",
"*://*.p.twitter.com/*"
],

"buttonSelectors": [
".twitter-share-button"
],
"replacementButton": {
"details": "https://twitter.com/intent/tweet?url=",
"imagePath": "Twitter.svg",
"type": 0
}
}
}
7 changes: 6 additions & 1 deletion src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ var Synchronizer = require("synchronizer").Synchronizer;
var Utils = require("utils").Utils;
var CookieBlockList = require("cookieblocklist").CookieBlockList;
var BlockedDomainList = require("blockedDomainList").BlockedDomainList;
var HeuristicBlocking = require("heuristicblocking")
var HeuristicBlocking = require("heuristicblocking");
var SocialWidgetLoader = require("socialwidgetloader");

// Load social widgets
var socialwidgets = SocialWidgetLoader.loadSocialWidgetsFromFile("socialwidgets.json");
console.log(socialwidgets);

// Some types cannot be distinguished
RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT;
Expand Down
76 changes: 76 additions & 0 deletions src/socialwidgetloader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
require.scopes["socialwidgetloader"] = (function() {

var exports = {};
exports.loadSocialWidgetsFromFile = loadSocialWidgetsFromFile;

/**
* Loads a JSON file at filePath and returns the parsed object.
*
* @param {String} filePath the path to the JSON file, relative to the
* extension's data folder
* @return {Object} the JSON at the file at filePath
*/
function loadJSONFromFile(filePath) {
var jsonString = getFileContents(filePath);
var jsonParsed = JSON.parse(jsonString);
Object.freeze(jsonParsed); // prevent modifications to jsonParsed

return jsonParsed;
}

/**
* Returns the contents of the file at filePath.
*
* @param {String} filePath the path to the file
*
* @return {String} the contents of the file
*/
function getFileContents(filePath) {
var url = chrome.extension.getURL(filePath);

var request = new XMLHttpRequest();
request.open("GET", url, false);
request.send();

return request.responseText;
}

/**
* Returns an array of SocialWidget objects that are loaded from the file at
* filePath.
*
* @param {String} filePath the path to the JSON file, relative to the
* extension's data folder
* @return {Array} an array of SocialWidget objects that are loaded from the file at
* filePath
*/
function loadSocialWidgetsFromFile(filePath) {
var socialwidgets = [];
var socialwidgetsJson = loadJSONFromFile(filePath);

// loop over each socialwidget, making a SocialWidget object
for (var socialwidgetName in socialwidgetsJson) {
var socialwidgetProperties = socialwidgetsJson[socialwidgetName];
var socialwidgetObject = new SocialWidget(socialwidgetName, socialwidgetProperties);
socialwidgets.push(socialwidgetObject);
}

return socialwidgets;
}

/**
* Constructs a SocialWidget with the given name and properties.
*
* @param {String} name the name of the socialwidget
* @param {Object} properties the properties of the socialwidget
*/
function SocialWidget(name, properties) {
this.name = name;

for (var property in properties) {
this[property] = properties[property];
}
}

return exports;
})(); //require scopes
Loading