Permalink
Browse files

Merge pull request #142 from ericawright/activity_stream_compat

Add gifs to Activity Stream!  
  • Loading branch information...
2 parents 7187a48 + 6038b7e commit 2857c6b7adb3b39acbf84188ddb00ddff6f1550e @bwinton committed on GitHub Jun 25, 2016
Showing with 29 additions and 14 deletions.
  1. +23 −10 data/newtabicons-content.js
  2. +6 −4 lib/newtabicons.js
@@ -9,17 +9,23 @@
'use strict';
function mouseOverListener(e) {
- let thumb = e.target.previousElementSibling;
+ var thumb = e.target.previousElementSibling || e.target;
+ if (thumb.classList.contains('tile-img-container')) {
+ thumb = thumb.querySelector('.site-icon-background');
+ }
thumb.style.backgroundImage = thumb.dataset.newPreview;
}
function mouseOutListener(e) {
- let thumb = e.target.previousElementSibling;
+ var thumb = e.target.previousElementSibling || e.target;
+ if (thumb.classList.contains('tile-img-container')) {
+ thumb = thumb.querySelector('.site-icon-background');
+ }
thumb.style.backgroundImage = thumb.dataset.oldPreview;
}
function mouseMoveListener (e) {
- var thumbnails = window.document.getElementsByClassName('newtab-cell');
+ var thumbnails = window.document.querySelectorAll(self.options.selectors);
for (let i = 0; i < thumbnails.length; ++i) {
let thumb = thumbnails[i];
let thumbs = thumb.getElementsByClassName('newtab-thumbnail');
@@ -37,7 +43,7 @@ function mouseMoveListener (e) {
}
function updateThumbnails() {
- var thumbnails = window.document.getElementsByClassName('newtab-cell');
+ var thumbnails = window.document.querySelectorAll(self.options.selectors);
if (thumbnails.length === 0) {
setTimeout(updateThumbnails, 500);
return;
@@ -73,25 +79,28 @@ function updateThumbnails() {
case 0:
thumb.style.backgroundImage = thumb.dataset.oldPreview;
thumb.removeEventListener('mouseover', mouseOverListener);
- thumb.removeEventListener('mouseout', mouseOutListener);
+ thumb.removeEventListener('mouseleave', mouseOutListener);
window.removeEventListener('mousemove', mouseMoveListener);
break;
case 1:
thumb.style.backgroundImage = thumb.dataset.oldPreview;
+ if (thumb.classList.contains('site-icon-background')){
+ thumb = thumb.parentNode;
+ }
thumb.addEventListener('mouseover', mouseOverListener);
- thumb.addEventListener('mouseout', mouseOutListener);
+ thumb.addEventListener('mouseleave', mouseOutListener);
window.removeEventListener('mousemove', mouseMoveListener);
break;
case 2:
thumb.style.backgroundImage = thumb.dataset.newPreview;
thumb.removeEventListener('mouseover', mouseOverListener);
- thumb.removeEventListener('mouseout', mouseOutListener);
+ thumb.removeEventListener('mouseleave', mouseOutListener);
window.addEventListener('mousemove', mouseMoveListener);
break;
case 3:
thumb.style.backgroundImage = thumb.dataset.oldPreview;
thumb.removeEventListener('mouseover', mouseOverListener);
- thumb.removeEventListener('mouseout', mouseOutListener);
+ thumb.removeEventListener('mouseleave', mouseOutListener);
window.removeEventListener('mousemove', mouseMoveListener);
}
}
@@ -101,13 +110,17 @@ function updateThumbnails() {
function addThumbnails(thumbnails) {
if (thumbnails.length === 0) {
setTimeout(function () {
- addThumbnails(window.document.getElementsByClassName('newtab-cell'));
+ addThumbnails(window.document.querySelectorAll(self.options.selectors));
}, 1000);
return;
}
for (let i = 0; i < thumbnails.length; ++i) {
let thumb = thumbnails[i];
+ if (thumb.querySelector('.site-icon-background')) {
+ thumb.querySelector('.site-icon.spotlight-icon').style.backgroundColor = 'transparent';
+ thumb.querySelector('.site-icon-background').style.backgroundColor = 'transparent';
+ }
let thumbs = thumb.getElementsByClassName('newtab-thumbnail');
if (!thumbs.length) {
thumbs = [thumb];
@@ -141,5 +154,5 @@ function overrideToggle() {
});
}
-addThumbnails(window.document.getElementsByClassName('newtab-cell'));
+addThumbnails(window.document.querySelectorAll(self.options.selectors));
overrideToggle();
View
@@ -17,6 +17,7 @@ var tabs = require('sdk/tabs');
var worker = null;
var menuitem; // Context menu item to copy thumbnail URL.
+const selectors = '.newtab-cell, .spotlight-image, .tile-img-container .site-icon-background';
const PRIVATE_THUMBS = [
'https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcQ87WpQQt7ddLZc9PcB_dIP23--m5UK3tJ-4-Wo-ExvzhOcFphy3g',
@@ -58,7 +59,7 @@ var addContentScript = function (tab) {
if (tab.url === 'about:privatebrowsing') {
tab.url = 'about:newtab';
}
- if (tab.url === 'about:newtab') {
+ if (tab.url === 'about:newtab'|| tab.url === 'resource://activity-streams/data/content/activity-streams.html#/') {
var thumbs = etherpad.getRandomItems(15);
if (privateBrowsing.isPrivate(tab)) {
thumbs = [
@@ -69,7 +70,8 @@ var addContentScript = function (tab) {
worker = tab.attach({
contentScriptFile: self.data.url('newtabicons-content.js'),
contentScriptOptions: { 'thumbs': thumbs,
- 'showPref': prefs.prefs.newtabicons2 }
+ 'showPref': prefs.prefs.newtabicons2,
+ 'selectors': selectors }
});
worker.port.on('toggle clicked', function () {
var pref = prefs.prefs.newtabicons2;
@@ -104,8 +106,8 @@ var addMenuItem = function () {
menuitem = cm.Item({
label: 'Copy Thumbnail URL',
context: [
- cm.URLContext('about:newtab'),
- cm.SelectorContext('.newtab-cell')
+ cm.URLContext(['resource://activity-streams/data/content/activity-streams.html#/', 'about:newtab']),
+ cm.SelectorContext(selectors)
],
contentScript: 'self.on("click", function(node, data) {\n' +
' let thumbs = node.getElementsByClassName("newtab-thumbnail");\n' +

0 comments on commit 2857c6b

Please sign in to comment.