experiments in a post-browser web
10
fork

Configure Feed

Select the types of activity you want to include in your feed.

updated to new SDK UI stuff, made URL list configurable instead of app tabs.

+98 -60
+9
data/panel.js
··· 2 2 var matches = window.document.querySelectorAll('a'); 3 3 for (var i = 0; i < matches.length; i++) 4 4 matches[i].setAttribute('target', '_blank'); 5 + 6 + window.addEventListener('click', function(event) { 7 + self.port.emit('click-link') 8 + /* 9 + var t = event.target 10 + if (t.nodeName == 'A') 11 + self.port.emit('click-link', t.toString()) 12 + */ 13 + }, false)
+80 -58
lib/main.js
··· 1 1 //const {Cc, Ci, Cu, Cm} = require('chrome') 2 - const { Hotkey } = require('hotkeys') 3 - const { Panel } = require('panel') 4 - const Data = require('self').data 5 - const Prefs = require('preferences-service') 6 - const Tabs = require('tabs') 2 + var { Hotkey } = require('sdk/hotkeys'), 3 + { Panel } = require('sdk/panel'), 4 + UI = require('sdk/ui'), 5 + { URL } = require('sdk/url'), 6 + Self = require('sdk/self'), 7 + Prefs = require('sdk/preferences/service'), 8 + AddonPrefs = require('sdk/simple-prefs'), 9 + TAB_PREF = 'browser.tabs.loadDivertedInBackground', 10 + COMBO_PREFIX = 'alt-shift-', 11 + lastPrefVal = null, 12 + hotkeys = [], 13 + windowHeight = null, 14 + windowWidth = null, 15 + BUTTON_TITLE = 'P' 16 + 17 + let prefsPanel = Panel({ 18 + contentURL: Self.data.url('prefs.html') 19 + }) 7 20 8 - const TAB_PREF = 'browser.tabs.loadDivertedInBackground' 9 - const COMBO = 'alt-shift-' 21 + let button = UI.ActionButton({ 22 + id: 'PeekPreferences', 23 + label: 'Peek Preferences', 24 + //contentURL: 'data:text/html,' + BUTTON_TITLE, 25 + icon: './icon.gif', 26 + onClick: function() { 27 + prefsPanel.show({ 28 + position: button 29 + }) 30 + } 31 + }) 10 32 11 - let inited, 12 - lastPrefVal, 13 - windowHeight, 14 - windowWidth 33 + // initialize 34 + var savedText = AddonPrefs.prefs['urls'] 35 + processText(savedText) 36 + prefsPanel.port.emit('text', savedText) 15 37 16 - let hotkey = Hotkey({ 17 - combo: 'accel-shift-o', 18 - onPress: function() { 19 - getPanel(Data.url('panel.html')).show() 20 - } 38 + prefsPanel.port.on('text', function(text) { 39 + AddonPrefs.prefs['urls'] = text 40 + processText(text) 41 + prefsPanel.hide() 21 42 }) 22 43 44 + function processText(text) { 45 + var parts = text.split('\n'), 46 + urls = [] 47 + 48 + parts.forEach(function(part) { 49 + try { 50 + var url = URL(part) 51 + urls.push(part) 52 + } catch(ex) { 53 + console.log('not a url', part) 54 + } 55 + }) 56 + 57 + addHotkeys(urls) 58 + } 59 + 60 + function addHotkeys(urls) { 61 + hotkeys.forEach(function(entry) { 62 + entry.hotkey.destroy() 63 + entry.panel.destroy() 64 + }) 65 + 66 + urls.forEach(function(url, i) { 67 + var panel = getPanel(url) 68 + hotkeys.push({ 69 + hotkey: Hotkey({ 70 + combo: COMBO_PREFIX + (i + 1), 71 + onPress: function() { 72 + panel.show() 73 + } 74 + }), 75 + panel: panel 76 + }) 77 + }) 78 + } 79 + 23 80 function getPanel(url) { 24 81 let panel = Panel({ 25 82 contentURL: url || 'about:blank', 26 83 height: 600, 27 84 width: 800, 28 - /* 29 - height: getPanelDimension(windowHeight), 30 - width: getPanelDimension(windowWidth), 31 - */ 32 - contentScriptFile: Data.url('panel.js'), 85 + //height: getPanelDimension(windowHeight), 86 + //width: getPanelDimension(windowWidth), 87 + contentScriptFile: Self.data.url('panel.js'), 33 88 contentScriptWhen: 'ready', 34 89 onShow: function() { 35 90 lastPrefVal = Prefs.get(TAB_PREF) ··· 39 94 onHide: function() { 40 95 if (lastPrefVal !== undefined && lastPrefVal != Prefs.get(TAB_PREF)) 41 96 Prefs.set(TAB_PREF, lastPrefVal) 42 - panel.destroy() 43 97 } 44 98 }) 99 + panel.on('click-link', function() { 100 + panel.hide() 101 + }) 45 102 return panel; 46 103 } 47 104 48 105 function getPanelDimension(amount) Math.round(amount * 0.9) 49 106 50 - /* 51 - // Window resize event handler 52 - function onResize(msg) { 53 - windowHeight = msg.height; 54 - windowWidth = msg.width; 55 - 56 - // Initializing on the first received resize event ensures 57 - // that it occurs for both running and startup installs. 58 - if (!inited) 59 - inited = true; 60 - } 61 - 62 - // When a tab activates, attach our content script 63 - // and remove when deactivated. Content script is for: 64 - // - getting window size 65 - function onTabActivate(tab) { 66 - let worker = tab.attach({ 67 - contentScriptFile: Data.url('content.js'), 68 - contentScriptWhen: 'ready' 69 - }); 70 - worker.port.on('resize', onResize); 71 - tab.on('deactivate', function(tab) { 72 - worker.destroy(); 73 - }); 74 - } 75 - 76 - // INITIALIZE 77 - // Handle current tab activation manually in case we're installed 78 - // in a running instance. This gets us initial window size which 79 - // triggers initial filling of cache. 80 - onTabActivate(Tabs.activeTab); 81 - 82 - // Listen for tab switching so we always have a resize handler 83 - // TODO: might be a window-level way of doing this nowadays 84 - Tabs.on('activate', onTabActivate); 85 - */ 107 + //require('onWindowResize').windowSize()
+9 -2
package.json
··· 2 2 "name": "peek", 3 3 "license": "MPL 1.1/GPL 2.0/LGPL 2.1", 4 4 "author": "Dietrich Ayala", 5 - "version": "2.1", 5 + "version": "3", 6 6 "fullName": "Peek", 7 7 "id": "jid1-xEAuRv8GzibUdw", 8 - "description": "Peek at your app tabs without breaking your flow." 8 + "description": "Peek at your favorite sites without breaking your flow.", 9 + "preferences": [{ 10 + "name": "urls", 11 + "title": "URLs", 12 + "type": "string", 13 + "value": "", 14 + "hidden": true 15 + }] 9 16 }