diff options
Diffstat (limited to 'content-script')
| -rw-r--r-- | content-script/.gitignore | 2 | ||||
| -rw-r--r-- | content-script/alone-off.png | bin | 1259 -> 0 bytes | |||
| -rw-r--r-- | content-script/alone-on.png | bin | 1271 -> 0 bytes | |||
| -rw-r--r-- | content-script/background.js | 135 | ||||
| -rw-r--r-- | content-script/check.js | 102 | ||||
| -rw-r--r-- | content-script/icon-128.png | bin | 15156 -> 0 bytes | |||
| -rw-r--r-- | content-script/icon-16.png | bin | 1490 -> 0 bytes | |||
| -rw-r--r-- | content-script/icon-48.png | bin | 3973 -> 0 bytes | |||
| -rw-r--r-- | content-script/index.html | 8 | ||||
| -rw-r--r-- | content-script/manifest.json | 29 | ||||
| -rw-r--r-- | content-script/options.html | 16 | ||||
| -rw-r--r-- | content-script/options.js | 34 |
12 files changed, 0 insertions, 326 deletions
diff --git a/content-script/.gitignore b/content-script/.gitignore deleted file mode 100644 index 5ca0973f..00000000 --- a/content-script/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.DS_Store - diff --git a/content-script/alone-off.png b/content-script/alone-off.png Binary files differdeleted file mode 100644 index 677b2273..00000000 --- a/content-script/alone-off.png +++ /dev/null diff --git a/content-script/alone-on.png b/content-script/alone-on.png Binary files differdeleted file mode 100644 index 7c0f441e..00000000 --- a/content-script/alone-on.png +++ /dev/null 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" - }) - } - } -}) - diff --git a/content-script/check.js b/content-script/check.js deleted file mode 100644 index 0644084d..00000000 --- a/content-script/check.js +++ /dev/null @@ -1,102 +0,0 @@ -(function(){ - - var listening = false, loaded = false - var TYPES = { Status: 0, Connected: 1, Disconnected: 2, Image: 3, Text: 4 } - var PUNCTUATION_REGEX = /[\[\]\{\}]/g // i.e. resembles code - var NULL_ARRAY = [] - var seen = {} - const toArray = (a) => Array.prototype.slice.call(a) - const $ = (s) => document.querySelector(s) - const $$ = (s) => document.querySelectorAll(s) - - function init () { - if (window.location.href.indexOf("lvh.me") !== -1 || window.location.href.indexOf("localhost") !== -1) return - bind() - } - function bind () { - chrome.extension.onMessage.addListener(onMessage) - chrome.extension.sendMessage({ type: TYPES.Status }, gotStatus) - } - function gotStatus (response) { - console.log('got status', response) - if (response && response.status === "on") { - console.log('its on', loaded) - if (! loaded) { - console.log('started') - setTimeout(() => { start() }, 5000) - // send(document.body.innerText) - // setInterval(function(){ - // send(document.body.innerText) - // }, 10000) - } - loaded = true - } - } - function onMessage (request, sender, sendResponse) { - switch (request.method) { - case 'start': - start() - break - case 'stop': - listening = false - break - } - } - function start(){ - console.log(window.location.href, listening) - if (window.location.href.indexOf('schol' + 'ar' + '.go' + 'og' + 'le') === -1) return - if (listening) return - listening = true - energize() - } - - function energize(){ - console.log('energize') - const records = toArray($$(".gs_r")).map((el, i) => { - let data = {} - let link = el.querySelector("h3 a") - if (link) { - data.link = link.href - } - let pdfLink = el.querySelector(".gs_or_ggsm a") - if (pdfLink) { - data.pdfLink = pdfLink.href - } - let attribution = el.querySelector('.gs_a') - if (attribution) { - data.attribution = attribution.innerText - data.attributionLinks = toArray(attribution.querySelectorAll('a')).map(a => ({ - href: a.href, - name: a.innerText, - })) - } - let snippet = el.querySelector('.gs_a') - if (snippet) { - data.snippet = snippet.innerText - } - let citationLink = el.querySelector('.gs_fl a:nth-of-type(3)') - if (citationLink && citationLink.innerText.match('Cited by')) { - data.citationLink = citationLink.href - data.citationCount = parseInt(citationLink.innerText.replace(/^\s*Cited by /, ''), 10) || -1 - } - return data - }) - let record = { - title: document.querySelector('title').innerText, - url: window.location.href, - records: records, - } - send(JSON.stringify(record)) - let nextLink = $("#gs_n td:last-child a") - if (nextLink) { - setTimeout(() => { nextLink.click() }, 19000 + (Math.random() * 21000)) - } - send("done") - } - function send (text) { - chrome.extension.sendMessage({ type: TYPES.Text, data: text }, function(){}) - } - - init() - -})() diff --git a/content-script/icon-128.png b/content-script/icon-128.png Binary files differdeleted file mode 100644 index 75ccfc80..00000000 --- a/content-script/icon-128.png +++ /dev/null diff --git a/content-script/icon-16.png b/content-script/icon-16.png Binary files differdeleted file mode 100644 index b2bfd098..00000000 --- a/content-script/icon-16.png +++ /dev/null diff --git a/content-script/icon-48.png b/content-script/icon-48.png Binary files differdeleted file mode 100644 index b4b752a7..00000000 --- a/content-script/icon-48.png +++ /dev/null diff --git a/content-script/index.html b/content-script/index.html deleted file mode 100644 index 577ab5b0..00000000 --- a/content-script/index.html +++ /dev/null @@ -1,8 +0,0 @@ -<!doctype html> -<html> -<head> -<script type="text/javascript" src="background.js"></script> -</head> -<body> -</body> -</html> diff --git a/content-script/manifest.json b/content-script/manifest.json deleted file mode 100644 index dc7e9c9b..00000000 --- a/content-script/manifest.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "Mego", - "version": "1.0.0", - "manifest_version": 2, - "description": "Mego content extension", - "homepage_url": "https://asdf.us/", - "icons": { "16": "icon-16.png", - "48": "icon-48.png", - "128": "icon-128.png" }, - "permissions": ["storage", "tabs", "webRequest", "*://*/*"], - "background": { - "page": "index.html" - }, - "content_scripts": [ - { - "matches": ["*://*/*"], - "js": ["check.js"] - } - ], - "browser_action": { - "name": "Start Mego", - "default_icon": "alone-on.png", - "icons": ["alone-on.png", "alone-off.png"] - }, - "options_ui": { - "page": "options.html", - "chrome_style": true - } -} diff --git a/content-script/options.html b/content-script/options.html deleted file mode 100644 index 8b5ba90c..00000000 --- a/content-script/options.html +++ /dev/null @@ -1,16 +0,0 @@ -<!DOCTYPE html> -<html> -<head> - <title>Alone Together Plugin Options</title> - <style> - body { padding: 10px; } - label { min-width: 90px; display: inline-block; } - #port { width: 50px; } - div { margin-bottom: 10px; } - </style> -</head> - -<body> -</body> - -</html>
\ No newline at end of file diff --git a/content-script/options.js b/content-script/options.js deleted file mode 100644 index ef9396fa..00000000 --- a/content-script/options.js +++ /dev/null @@ -1,34 +0,0 @@ -// Saves options to chrome.storage.sync. -function $(n) { return document.querySelector(n) } -function save_options() { - chrome.storage.sync.set({ - server: $("#server").value, - port: parseInt( $("#port").value, 10 ), - name: $("#name").value, - }, function() { - // Update status to let user know options were saved. - var status = document.getElementById('status'); - status.textContent = 'Options saved.'; - setTimeout(function() { - status.textContent = ''; - }, 750); - }); -} - -// Restores select box and checkbox state using the preferences -// stored in chrome.storage. -function restore_options() { - chrome.storage.sync.get({ - server: 'localhost', - port: 3000, - name: 'whomever', - }, function(items) { - console.log(items) - "server port name".split(" ").forEach(function(id){ - $("#"+id).value = items[id] - }) - }); -} -document.addEventListener('DOMContentLoaded', restore_options); -document.getElementById('save').addEventListener('click', save_options); -console.log("WHAT") |
