master
remy 3 years ago
parent 2fcfb91a2b
commit 93937c2194
  1. 11
      README.md
  2. 20
      manifest.json
  3. 100
      package-lock.json
  4. 19
      project.zsh
  5. 53
      src/main.ls
  6. 74
      src/websocketd-ws.ls

@ -1,3 +1,12 @@
# test_broswer_plugin
Test de création d'un plugin pour firefox lié a websocketd
Test de création d'un plugin pour firefox lié a websocketd
POC fonctionnel sur la base de trackingd
## Pour l'installation si trackind fonctionne !
npm install
build.zsh
make

@ -0,0 +1,20 @@
{
"manifest_version": 2,
"name": "Borderify",
"version": "1.0",
"description": "Adds a solid red border to all webpages matching mozilla.org.",
"icons": {
"48": "icons/border-48.png"
},
"content_scripts": [
{
"matches": ["*://*.mozilla.org/*"],
"js": ["public/main.bundle.js"]
}
]
}

100
package-lock.json generated

@ -0,0 +1,100 @@
{
"requires": true,
"lockfileVersion": 1,
"dependencies": {
"browserify-livescript": {
"version": "0.2.4",
"resolved": "https://registry.npmjs.org/browserify-livescript/-/browserify-livescript-0.2.4.tgz",
"integrity": "sha512-xbHGs4l2RSCxY/WN1PKxmHtMc2ri95KWSgXgNF3ieADAuOe0KRpAppoz5+A4Klzhww9yQh7oOes8h+9Lr619fQ==",
"requires": {
"livescript": "^1.6.0",
"through": "*"
}
},
"buffer-from": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A=="
},
"deep-is": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz",
"integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ="
},
"fast-levenshtein": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz",
"integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc="
},
"levn": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz",
"integrity": "sha1-OwmSTt+fCDwEkP3UwLxEIeBHZO4=",
"requires": {
"prelude-ls": "~1.1.2",
"type-check": "~0.3.2"
}
},
"livescript": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/livescript/-/livescript-1.6.0.tgz",
"integrity": "sha512-x5q+sx1/rOPmx6Fp04gjUqRr4XL5djqXPctu6FPBktm7d7gfRrKkYj9PhMeKT8OKE1bfL92njzAwaN8JCj8kRQ==",
"requires": {
"optionator": "~0.8.2",
"prelude-ls": "~1.1.2",
"source-map": "=0.6.1",
"source-map-support": "=0.5.6"
}
},
"optionator": {
"version": "0.8.3",
"resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.3.tgz",
"integrity": "sha512-+IW9pACdk3XWmmTXG8m3upGUJst5XRGzxMRjXzAuJ1XnIFNvfhjjIuYkDvysnPQ7qzqVzLt78BCruntqRhWQbA==",
"requires": {
"deep-is": "~0.1.3",
"fast-levenshtein": "~2.0.6",
"levn": "~0.3.0",
"prelude-ls": "~1.1.2",
"type-check": "~0.3.2",
"word-wrap": "~1.2.3"
}
},
"prelude-ls": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz",
"integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ="
},
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="
},
"source-map-support": {
"version": "0.5.6",
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.6.tgz",
"integrity": "sha512-N4KXEz7jcKqPf2b2vZF11lQIz9W5ZMuUcIOGj243lduidkf2fjkVKJS9vNxVWn3u/uxX38AcE8U9nnH9FPcq+g==",
"requires": {
"buffer-from": "^1.0.0",
"source-map": "^0.6.0"
}
},
"through": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
"integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU="
},
"type-check": {
"version": "0.3.2",
"resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz",
"integrity": "sha1-WITKtRLPHTVeP7eE8wgEsrUg23I=",
"requires": {
"prelude-ls": "~1.1.2"
}
},
"word-wrap": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz",
"integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ=="
}
}
}

@ -0,0 +1,19 @@
package=test-pluging
version=0.1.0
targets=(public/main.js)
type[public/main.js]=livescript
sources[public/main.js]=src/main.ls
depends[public/main.js]="$(find src | grep '\.ls$' | grep -v "/main.ls$" | tr '\n' ' ' )"
for ext in eot woff2 woff ttf svg; do
for style in solid-900 regular-400 light-300; do
t=public/fa-${style}.${ext}
targets+=($t)
type[$t]=script
sources[$t]=node_modules/@fortawesome/fontawesome-pro/webfonts/$(basename $t)
done
done

@ -0,0 +1,53 @@
WebsocketdWS = require "./websocketd-ws.ls"
a = WebsocketdWS "trackingd", "ws://localhost:9998/tracking.JSON"
storage = window.local-storage
request-types = { #client to server
"get-token": 0
"session-init": 11
"action": 20
"url-action": 21
}
response-types = { #server to client
"error": 0
"default-id": 10
"action": 12
}
for name, value of response-types
a.register-response-type value, name
a.on-default-id = (payload) ->
console.log payload.default_id
unless storage.get-item "visitor_id"
storage.set-item "visitor_id", payload.default_id
a.send request-types[\session-init], JSON.stringify {
visitor_id: storage.get-item "visitor_id"
user_agent: window.navigator.userAgent
resolution_height: window.screen.availHeight
resolution_width: window.screen.availWidth
referrer: document.referrer
}
a.action = (action) ->
a.send request-types[\action], JSON.stringify {
action: action
}
a.urlaction = (urlaction) ->
a.send request-types[\url-action], JSON.stringify {
urlaction: urlaction
}
a.urlaction "blabla.com0"
#a.action "blabla.com"
a.on-error = (message) ->
console.error "Error received: #{message.reason}"

@ -0,0 +1,74 @@
pascal-case = (string) ->
string.replace /^./g, ((.to-upper-case!))
.replace /-(.)/g, (m, m1) -> m1.to-upper-case!
module.exports = (socket-name, socket-url) ->
self = {}
request-types = {}
response-types = {}
delayed-messages = []
# TODO: naming convention
# users can record functions to run on events
self.user-on-socket-error = []
self.user-on-socket-close = []
self.open-socket = ->
self.socket := new WebSocket socket-url
self.socket.onerror = (event) ->
for f in self.user-on-socket-error
f event
self.socket.close!
self.socket.onclose = (event) ->
for f in self.user-on-socket-close
f event
self.socket.onmessage = (event) ->
message = JSON.parse(event.data)
key = "on" + pascal-case (response-types[message.utype] || "unknown-message")
payload = JSON.parse message.payload
console.log socket-name, message.utype, key, payload
if callback = self[key]
callback payload
self.socket.onopen = ->
delayed-messages.for-each (pair) ->
[type, opts] = pair
self.real-send type, opts
delayed-messages := []
self.reopen = ->
self.socket.close!
self.open-socket!
self.open-socket!
self.send = (type, opts) ->
if self.socket.ready-state
self.real-send type, opts
else
delayed-messages.push [type, opts]
self.real-send = (type, opts) ->
self.socket.send JSON.stringify { utype: type, payload: opts }
self.register-response-type = (type, type-name) ->
response-types[type] = type-name
self.close = ->
self.socket.close!
self
Loading…
Cancel
Save