Skip to content

Commit

Permalink
now the extension icon appears in the address bar only on twitter
Browse files Browse the repository at this point in the history
  • Loading branch information
tekool committed Nov 13, 2013
1 parent 7cd9c95 commit cdb44e9
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 105 deletions.
33 changes: 3 additions & 30 deletions chrome/background.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,6 @@
chrome.extension.onMessage.addListener( function(message, sender){

if(!message)
return;

switch( message.type)
{
case 'showPageAction':
chrome.pageAction.show(sender.tab.id);
break;

case 'showPreview':
{
//image previews
sheet.addRule(".js-stream-item .media > .media-thumbnail.is-preview > img", 'display:none !important;');
sheet.addRule(".js-stream-item.open .media > .media-thumbnail.is-preview > img", 'display:inline-block !important');

//video previews
sheet.addRule(".js-stream-item > .content > .expanded-content > .tweet-details-fixer > .js-media-container[data-card2-name='player']", 'display:none !important;');
sheet.addRule(".js-stream-item.open > .content > .expanded-content > .tweet-details-fixer > .js-media-container[data-card2-name='player']", 'display:inline-block !important;');
}
break;

case 'showPromoted':
{
sheet.addRule(".trends .promoted-trend", 'display:none !important;');
sheet.addRule(".js-stream-item .content .js-action-profile-promoted", 'display:none !important;');
sheet.addRule(".wtf-module .promoted-account", 'display:none !important;');
}
}
chrome.extension.onMessage.addListener( function( request, sender, sendResponse ){
if( request === "showPageAction" )
chrome.pageAction.show(sender.tab.id);
});

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
Expand Down
27 changes: 15 additions & 12 deletions chrome/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"short_name": "Twean",
"version": "1.2.0",
"description": "Remove images previews and promoted content from Twitter timeline.",
"author":"Tekool - Frédéric Saunier",
"author":"Tekool - Frédéric Saunier - www.tekool.net",
"homepage_url" :"https://github.com/tekool/twean",

"content_scripts":
Expand All @@ -18,26 +18,29 @@
}
],

"icons" : {
"19": "icon19.png",
"38" : "icon38.png",
"48" : "icon48.png",
"128" : "icon128.png"
"icons" :
{
"19": "icon/icon19.png",
"38" : "icon/icon38.png",
"48" : "icon/icon48.png",
"128" : "icon/icon128.png"
},

"page_action":
{
"default_title": "Twean",
"default_icon": {
"19": "icon19.png",
"38" : "icon38.png",
"48" : "icon48.png",
"128" : "icon128.png"
"default_icon":
{
"19": "icon/icon19.png",
"38" : "icon/icon38.png",
"48" : "icon/icon48.png",
"128" : "icon/icon128.png"
},
"default_popup": "options.html"
},

"background": {
"background":
{
"scripts": ["background.js"]
},

Expand Down
34 changes: 34 additions & 0 deletions chrome/options.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
html, body
{
width:250px;
height:80px;
overflow:hidden;
}

body
{
font-family: "Helvetic Neue", Helvetica, Arial;
font-size: 0.8em;
padding:5px;
}

.icon{

position:absolute;
top:5px;
left:190px;
background: url(icon/icon48.png) no-repeat;
opacity:0.5;
}

@-webkit-keyframes bounce
{
0% {background: #ffffff;}
50% {background: #d9ffd6;}
100% {background: #ffffff;}
}

.saved
{
-webkit-animation: bounce 1s linear;
}
38 changes: 2 additions & 36 deletions chrome/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,7 @@
<head>

<title>Twean Options</title>
<style type="text/css">
² html, body
{
width:250px;
height:80px;
overflow:hidden;
}

body
{
font-family: "Helvetic Neue", Helvetica, Arial;
font-size: 0.8em;
padding:5px;
}

.icon{

position:absolute;
top:5px;
left:220px;
background: url(icon/icon48.png) no-repeat;
opacity:0.5;
}

@-webkit-keyframes bounce
{
0% {background: #ffffff;}
50% {background: lightgreen;}
100% {background: #ffffff;}
}

.saved
{
-webkit-animation: bounce 1s linear;
}
</style>
<link rel="stylesheet" href="options.css" type="text/css">

</head>

Expand All @@ -55,4 +20,5 @@
</body>

<script src="options.js"></script>

</html>
13 changes: 7 additions & 6 deletions chrome/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@
localStorage["promoted"] = !!promoted.checked;

document.body.classList.add("saved");
setTimeout(function(){document.body.classList.remove("saved")},1050)
setTimeout(function(){document.body.classList.remove("saved")},1050);

chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, "refresh");
});
}

// Restores select box state to saved value from localStorage.
function restore()
{
var hasPreviews = localStorage["previews"] || true;
var hasPromoted = localStorage["promoted"] || true;

previews.checked = hasPreviews;
promoted.checked = hasPromoted;
previews.checked = localStorage["previews"] || true;
promoted.checked = localStorage["promoted"] || true;
}

document.addEventListener('DOMContentLoaded', restore);
Expand Down
64 changes: 43 additions & 21 deletions chrome/page.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,58 @@
new Function()
{
chrome.extension.sendMessage({type:'showPageAction'});

var preview = localStorage["preview"] || true;
var promoted = localStorage["promoted"] || true;
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse){
if( request === "refresh" )
refresh();
});
//Display icon on the address bar when page script is loaded.
chrome.extension.sendMessage("showPageAction");

//Injected by the extension even before the <head/> element exists
var sheet = document.getElementsByTagName("html")[0].appendChild(document.createElement("style")).sheet;

//image and video previews
if( preview )
chrome.extension.sendMessage({type:'showPreview'});
var show = 'display:inline-block !important';
var hide = 'display:none !important;';
var rules =
{
imagePreview : ".js-stream-item .media > .media-thumbnail.is-preview > img",
imagePreviewOpen : ".js-stream-item.open .media > .media-thumbnail.is-preview > img",
videoPreview : ".js-stream-item > .content > .expanded-content > .tweet-details-fixer > .js-media-container[data-card2-name='player']",
videoPreviewOpen : ".js-stream-item.open > .content > .expanded-content > .tweet-details-fixer > .js-media-container[data-card2-name='player']",
promotedTrend: ".trends .promoted-trend",
promotedTweet: ".js-stream-item .content .js-action-profile-promoted",
promotedPeople: ".wtf-module .promoted-account"
};

//promoted content
if( promoted )
chrome.extension.sendMessage({type:'showPromoted'});
sheet.addRule( rules.imagePreviewOpen, show );
sheet.addRule( rules.videoPreviewOpen, show );

function showPreview()
function refresh()
{
//image previews
sheet.addRule(".js-stream-item .media > .media-thumbnail.is-preview > img", 'display:none !important;');
sheet.addRule(".js-stream-item.open .media > .media-thumbnail.is-preview > img", 'display:inline-block !important');
var preview = localStorage["preview"] || true;
var promoted = localStorage["promoted"] || true;

removeRules();

//video previews
sheet.addRule(".js-stream-item > .content > .expanded-content > .tweet-details-fixer > .js-media-container[data-card2-name='player']", 'display:none !important;');
sheet.addRule(".js-stream-item.open > .content > .expanded-content > .tweet-details-fixer > .js-media-container[data-card2-name='player']", 'display:inline-block !important;');
//image and video previews
if( preview )
{
sheet.addRule(rules.imagePreview, hide );
sheet.addRule(rules.videoPreview, hide );
}

//promoted content
if( promoted )
{
sheet.addRule(rules.promotedPeople, hide);
sheet.addRule(rules.promotedTrend, hide);
sheet.addRule(rules.promotedTweet, hide);
}
}

function showPromoted()
function removeRules()
{
sheet.addRule(".trends .promoted-trend", 'display:none !important;');
sheet.addRule(".js-stream-item .content .js-action-profile-promoted", 'display:none !important;');
sheet.addRule(".wtf-module .promoted-account", 'display:none !important;');

}

refresh();
}

0 comments on commit cdb44e9

Please sign in to comment.