summaryrefslogtreecommitdiff
path: root/content-script/background.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-11-25 22:19:15 +0100
committerJules Laplace <julescarbon@gmail.com>2018-11-25 22:19:15 +0100
commitee3d0d98e19f1d8177d85af1866fd0ee431fe9ea (patch)
tree41372528e78d4328bc2a47bbbabac7e809c58894 /content-script/background.js
parent255b8178af1e25a71fd23703d30c0d1f74911f47 (diff)
moving stuff
Diffstat (limited to 'content-script/background.js')
-rw-r--r--content-script/background.js135
1 files changed, 0 insertions, 135 deletions
diff --git a/content-script/background.js b/content-script/background.js
deleted file mode 100644
index 78244b12..00000000
--- a/content-script/background.js
+++ /dev/null
@@ -1,135 +0,0 @@
-// this script talks to the button, tells whether it is off or on,
-// and communicates this state to the open tabs
-
-var on = true;
-var TYPES = { Status: 0, Connected: 1, Disconnected: 2, Image: 3, Text: 4 }
-
-chrome.browserAction.onClicked.addListener(function(tab) {
- on = ! on
- if (on) {
- localStorage.setItem("megapixels", "on")
- chrome.browserAction.setIcon({path: 'alone-on.png'})
- chrome.browserAction.setTitle({title: "Stop Mego"});
- chrome.tabs.getSelected(null, function(tab) {
- chrome.tabs.sendMessage(tab.id, {method:"start"}, function(response){})
- })
- }
- else {
- localStorage.setItem("megapixels", "off")
- chrome.browserAction.setIcon({path: 'alone-off.png'})
- chrome.browserAction.setTitle({title: "Start Mego"})
- chrome.tabs.getSelected(null, function(tab) {
- chrome.tabs.sendMessage(tab.id, {method:"stop"}, function(response){})
- })
- }
-});
-
-// websocket boilerplate
-// var ws, ws_timeout, ws_delay = 500, opt = {}
-// function reset () {
-// close()
-// clearTimeout(ws_timeout)
-// ws_delay = Math.min(ws_delay*2, 60000)
-// ws_timeout = setTimeout(open, ws_delay)
-// }
-// function open () {
-// close()
-// ws = new WebSocket('ws://' + opt.server + ':' + opt.port)
-// ws.onopen = function (event) {
-// ws_delay = 500
-// send({ type: TYPES.Connected, data: { client: "browser" } })
-// console.log('websocket open')
-// }
-// ws.onerror = function () {
-// reset()
-// }
-// ws.onclose = function () {
-// reset()
-// }
-// }
-// function close () {
-// try {
-// ws.close()
-// ws = null
-// } catch (e) {}
-// }
-// function send (msg, force) {
-// msg.name = opt.name
-// if ( (on || force) && ws ) ws.send(JSON.stringify(msg))
-// }
-
-// // load options and connect websocket
-// chrome.storage.sync.get({
-// server: 'localhost',
-// port: 3000,
-// name: 'whomever',
-// }, function(items) {
-// console.log(items)
-// "server port name".split(" ").forEach(function(id){
-// opt[id] = items[id]
-// })
-// open()
-// });
-
-// chrome.storage.onChanged.addListener(function(changes, ns) {
-// for (key in changes) {
-// var change = changes[key]
-// opt[key] = change.newValue
-// }
-// open()
-// });
-
-// // listen for image urls
-// chrome.webRequest.onResponseStarted.addListener(function(details) {
-// send({ type: TYPES.Image, data: details.url })
-// }, {
-// urls: ["<all_urls>"],
-// types: ["image"]
-// }, ["responseHeaders"]);
-
-function push(s){
- console.log(s)
- let d = localStorage.getItem('site')
- if (s === 'done') {
- download('[' + localStorage.getItem('site') + ']')
- return
- }
- if (d) s = d + ',' + s
- localStorage.setItem('site', s)
-}
-function reset(){
- localStorage.setItem('site', '')
-}
-function download(content, fileName, contentType) {
- var a = document.createElement("a");
- var file = new Blob([JSON.stringify(content)], {type: contentType});
- a.href = URL.createObjectURL(file);
- a.download = fileName;
- a.click();
-}
-
-// new pages will check if we're listening
-chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
- console.log(request)
- switch (request.type) {
- case TYPES.Status:
- sendResponse({ status: localStorage['megapixels'] })
- break
- case TYPES.Text:
- push(request.data)
- break
- }
-});
-
-// injects check.js into tabs if not already loaded
-chrome.tabs.query({}, function(tabs) {
- for (var i = 0; i < tabs.length; i++) {
- var tabid = tabs[i].id;
- if (tabs[i].url.indexOf("chrome") === -1) {
- chrome.tabs.executeScript(tabid, {
- file: "check.js"
- })
- }
- }
-})
-