summaryrefslogtreecommitdiff
path: root/content-script/check.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/check.js
parent255b8178af1e25a71fd23703d30c0d1f74911f47 (diff)
moving stuff
Diffstat (limited to 'content-script/check.js')
-rw-r--r--content-script/check.js102
1 files changed, 0 insertions, 102 deletions
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()
-
-})()