WIP tig-spy
This commit is contained in:
4
projects/tig-spy/.gitignore
vendored
Normal file
4
projects/tig-spy/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
bin/
|
||||||
|
libs/
|
||||||
|
node_modules/
|
||||||
|
*.zip
|
12
projects/tig-spy/build.hxml
Normal file
12
projects/tig-spy/build.hxml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
-lib kiss
|
||||||
|
-lib kiss-firefox
|
||||||
|
-lib webextension-polyfill
|
||||||
|
-cp src
|
||||||
|
-dce full
|
||||||
|
--each
|
||||||
|
--main tig_spy.Main
|
||||||
|
--js bin/main.js
|
||||||
|
--next
|
||||||
|
--main tig_spy.Background
|
||||||
|
--js bin/background.js
|
||||||
|
-cmd cp node_modules/webextension-polyfill/dist/browser-polyfill.js* bin/ && zip -r template.zip . -x *.git* -x *.hxml -x *.zip -x src/\* -x node_modules/\* -x libs/\* -x test.sh
|
BIN
projects/tig-spy/icons/icon-48.png
Normal file
BIN
projects/tig-spy/icons/icon-48.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 225 B |
30
projects/tig-spy/manifest.json
Normal file
30
projects/tig-spy/manifest.json
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"name": "tig-spy",
|
||||||
|
"description": "analytics for TIGForum dev logs",
|
||||||
|
"icons": {
|
||||||
|
"48": "icons/icon-48.png"
|
||||||
|
},
|
||||||
|
"background": {
|
||||||
|
"scripts": [
|
||||||
|
"bin/browser-polyfill.js",
|
||||||
|
"bin/background.js"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"content_scripts": [
|
||||||
|
{
|
||||||
|
"js": [
|
||||||
|
"bin/browser-polyfill.js",
|
||||||
|
"bin/main.js"
|
||||||
|
],
|
||||||
|
"matches": [
|
||||||
|
"*://forums.tigsource.com/index.php?topic=*.0"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"permissions": [
|
||||||
|
"<all_urls>",
|
||||||
|
"tabs"
|
||||||
|
],
|
||||||
|
"version": "0.0",
|
||||||
|
"manifest_version": 2
|
||||||
|
}
|
16
projects/tig-spy/package.json
Normal file
16
projects/tig-spy/package.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"main": "index.js",
|
||||||
|
"name": "tig-spy",
|
||||||
|
"description": "analytics for TIGForum dev logs",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/webextension-polyfill": "^0.10.0",
|
||||||
|
"webextension-polyfill": "^0.10.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"dts2hx": "^0.19.0"
|
||||||
|
},
|
||||||
|
"version": "0.0.0",
|
||||||
|
"scripts": {
|
||||||
|
"postinstall": "dts2hx --all"
|
||||||
|
}
|
||||||
|
}
|
8
projects/tig-spy/src/tig_spy/Background.hx
Normal file
8
projects/tig-spy/src/tig_spy/Background.hx
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package tig_spy;
|
||||||
|
|
||||||
|
import kiss.Prelude;
|
||||||
|
import kiss_firefox.API;
|
||||||
|
import haxe.Constraints;
|
||||||
|
|
||||||
|
@:build(kiss.Kiss.build())
|
||||||
|
class Background {}
|
7
projects/tig-spy/src/tig_spy/Background.kiss
Normal file
7
projects/tig-spy/src/tig_spy/Background.kiss
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
(load "Util.kiss")
|
||||||
|
|
||||||
|
(API.browser.runtime.onMessage.addListener ->[message sender sendResponse] {
|
||||||
|
(let [:Function sendResponse (cast sendResponse)]
|
||||||
|
(sendResponse message))
|
||||||
|
true
|
||||||
|
})
|
7
projects/tig-spy/src/tig_spy/Main.hx
Normal file
7
projects/tig-spy/src/tig_spy/Main.hx
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package tig_spy;
|
||||||
|
|
||||||
|
class Main {
|
||||||
|
static function main() {
|
||||||
|
Main_.main();
|
||||||
|
}
|
||||||
|
}
|
69
projects/tig-spy/src/tig_spy/Main_.kiss
Normal file
69
projects/tig-spy/src/tig_spy/Main_.kiss
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
(import kiss_firefox.API)
|
||||||
|
(import js.lib.Promise)
|
||||||
|
|
||||||
|
(load "Util.kiss")
|
||||||
|
|
||||||
|
(var :Dynamic document js.Lib.global.document)
|
||||||
|
(var :Dynamic window js.Lib.global.window)
|
||||||
|
|
||||||
|
(function p [text]
|
||||||
|
(let [element (document.createElement "p")]
|
||||||
|
(set element.innerHTML text)
|
||||||
|
element))
|
||||||
|
|
||||||
|
(function printPostStats [:Array<String> authors]
|
||||||
|
(let [op (first authors)
|
||||||
|
:Map<String,Bool> repliers (new Map)
|
||||||
|
&mut updates 0
|
||||||
|
&mut replies 0]
|
||||||
|
(doFor author authors
|
||||||
|
(cond
|
||||||
|
((= op author)
|
||||||
|
(+= updates 1))
|
||||||
|
(true
|
||||||
|
(dictSet repliers author true)
|
||||||
|
(+= replies 1))))
|
||||||
|
(print "$updates updates by OP")
|
||||||
|
(print "$replies replies by $(count repliers) followers")))
|
||||||
|
|
||||||
|
(let [analyticsLink (document.createElement "a")]
|
||||||
|
(analyticsLink.addEventListener "click"
|
||||||
|
->:Void {
|
||||||
|
(let [analyticsDiv (document.createElement "div")]
|
||||||
|
(document.body.prepend analyticsDiv)
|
||||||
|
(set Prelude.printStr ->s (analyticsDiv.appendChild (p s))))
|
||||||
|
|
||||||
|
(let [:String subjectLine .innerHTML (document.getElementById "top_subject")
|
||||||
|
lastLeftParenIndex (subjectLine.lastIndexOf "(")
|
||||||
|
lastRightParenIndex (subjectLine.lastIndexOf ")")
|
||||||
|
[Read n times] (.split (substr subjectLine lastLeftParenIndex lastRightParenIndex) " ")]
|
||||||
|
(print "$n views"))
|
||||||
|
|
||||||
|
|
||||||
|
(let [:String url
|
||||||
|
window.location.href
|
||||||
|
urlWithoutStartingPost0
|
||||||
|
(substr url 0 -1)
|
||||||
|
postsPerPage
|
||||||
|
20
|
||||||
|
navPageElements
|
||||||
|
(document.getElementsByClassName "navPages")
|
||||||
|
numPages
|
||||||
|
(if (< 0 navPageElements.length)
|
||||||
|
(Std.parseInt .innerHTML (nth navPageElements (- navPageElements.length 1)))
|
||||||
|
1)]
|
||||||
|
(for page (range 1 numPages)
|
||||||
|
(let [pageUrl "${urlWithoutStartingPost0}$(* page postsPerPage)"]
|
||||||
|
(awaitLet [resp (API.browser.runtime.sendMessage pageUrl)]
|
||||||
|
~resp))))
|
||||||
|
|
||||||
|
(printPostStats (postAuthors document))
|
||||||
|
|
||||||
|
})
|
||||||
|
(set analyticsLink.innerHTML "Run analytics")
|
||||||
|
(document.body.prepend analyticsLink))
|
||||||
|
|
||||||
|
(API.browser.runtime.onMessage.addListener
|
||||||
|
->[message sender sendResponse] {
|
||||||
|
~message
|
||||||
|
})
|
13
projects/tig-spy/src/tig_spy/Util.kiss
Normal file
13
projects/tig-spy/src/tig_spy/Util.kiss
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
(function postElements [:Dynamic document]
|
||||||
|
(let [postTable (.item (document.getElementsByClassName "bordercolor") 0)
|
||||||
|
postTableBody (postTable.children.item 0)
|
||||||
|
tableRows (for i (range postTableBody.children.length) (postTableBody.children.item i))]
|
||||||
|
// There is an empty row at the end:
|
||||||
|
(tableRows.pop)
|
||||||
|
tableRows))
|
||||||
|
|
||||||
|
(function postAuthors [:Dynamic document]
|
||||||
|
(for [idx post] (enumerate (postElements document))
|
||||||
|
(let [links (post.getElementsByTagName "a")
|
||||||
|
userLink (links.item (min idx 1))]
|
||||||
|
userLink.innerHTML)))
|
7
projects/tig-spy/test.sh
Executable file
7
projects/tig-spy/test.sh
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
if [ ! -d node_modules ]; then
|
||||||
|
$(haxelib libpath kiss)/build-scripts/dts2hx-externs/regenerate.sh
|
||||||
|
fi
|
||||||
|
|
||||||
|
haxe -D test build.hxml
|
Reference in New Issue
Block a user