Start pixabay-sourcer extension
This commit is contained in:
12
build.hxml
Normal file
12
build.hxml
Normal file
@@ -0,0 +1,12 @@
|
||||
-lib kiss
|
||||
-lib kiss-firefox
|
||||
-cp externs
|
||||
-cp src
|
||||
-dce full
|
||||
--each
|
||||
--main pixabay_sourcer.Main
|
||||
--js bin/main.js
|
||||
--next
|
||||
--main pixabay_sourcer.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
|
5
haxe_libraries/haxe-strings.hxml
Normal file
5
haxe_libraries/haxe-strings.hxml
Normal file
@@ -0,0 +1,5 @@
|
||||
# @install: lix --silent download "haxelib:/haxe-strings#7.0.2" into haxe-strings/7.0.2/haxelib
|
||||
-cp ${HAXE_LIBCACHE}/haxe-strings/7.0.2/haxelib/src/
|
||||
-D haxe-strings=7.0.2
|
||||
--macro hx.strings.internal.Macros.addDefines()
|
||||
--macro hx.strings.internal.Macros.configureNullSafety()
|
5
haxe_libraries/hscript.hxml
Normal file
5
haxe_libraries/hscript.hxml
Normal file
@@ -0,0 +1,5 @@
|
||||
# @install: lix --silent download "haxelib:/hscript#2.5.0" into hscript/2.5.0/haxelib
|
||||
# @run: haxelib run-dir hscript "${HAXE_LIBCACHE}/hscript/2.5.0/haxelib"
|
||||
-cp ${HAXE_LIBCACHE}/hscript/2.5.0/haxelib/
|
||||
-D hscript=2.5.0
|
||||
--macro keep('IntIterator')
|
4
haxe_libraries/kiss-firefox.hxml
Normal file
4
haxe_libraries/kiss-firefox.hxml
Normal file
@@ -0,0 +1,4 @@
|
||||
# @install: lix --silent download "gh://github.com/kiss-lang/kiss-firefox#a81ba4bfd2a5d5ec454e0d49c6bfcc8a332c2bae" into kiss-firefox/0.0.0/github/a81ba4bfd2a5d5ec454e0d49c6bfcc8a332c2bae
|
||||
-lib kiss
|
||||
-cp ${HAXE_LIBCACHE}/kiss-firefox/0.0.0/github/a81ba4bfd2a5d5ec454e0d49c6bfcc8a332c2bae/src/
|
||||
-D kiss-firefox=0.0.0
|
12
haxe_libraries/kiss.hxml
Normal file
12
haxe_libraries/kiss.hxml
Normal file
@@ -0,0 +1,12 @@
|
||||
# @install: lix --silent download "gh://github.com/kiss-lang/kiss#a6c0cf88c6a02aa7845dca7c5c5025b915b78fbc" into kiss/0.0.1/github/a6c0cf88c6a02aa7845dca7c5c5025b915b78fbc
|
||||
# @run: haxelib run-dir kiss "${HAXE_LIBCACHE}/kiss/0.0.1/github/a6c0cf88c6a02aa7845dca7c5c5025b915b78fbc"
|
||||
-lib haxe-strings
|
||||
-lib hscript
|
||||
-lib tink_json
|
||||
-lib tink_macro
|
||||
-lib tink_syntaxhub
|
||||
-lib uuid
|
||||
-cp ${HAXE_LIBCACHE}/kiss/0.0.1/github/a6c0cf88c6a02aa7845dca7c5c5025b915b78fbc/src/
|
||||
-D kiss=0.0.1
|
||||
-w -WUnusedPattern
|
||||
--macro kiss.KissFrontend.use()
|
3
haxe_libraries/tink_core.hxml
Normal file
3
haxe_libraries/tink_core.hxml
Normal file
@@ -0,0 +1,3 @@
|
||||
# @install: lix --silent download "haxelib:/tink_core#2.1.0" into tink_core/2.1.0/haxelib
|
||||
-cp ${HAXE_LIBCACHE}/tink_core/2.1.0/haxelib/src
|
||||
-D tink_core=2.1.0
|
4
haxe_libraries/tink_json.hxml
Normal file
4
haxe_libraries/tink_json.hxml
Normal file
@@ -0,0 +1,4 @@
|
||||
# @install: lix --silent download "haxelib:/tink_json#0.11.0" into tink_json/0.11.0/haxelib
|
||||
-lib tink_typecrawler
|
||||
-cp ${HAXE_LIBCACHE}/tink_json/0.11.0/haxelib/src
|
||||
-D tink_json=0.11.0
|
4
haxe_libraries/tink_macro.hxml
Normal file
4
haxe_libraries/tink_macro.hxml
Normal file
@@ -0,0 +1,4 @@
|
||||
# @install: lix --silent download "haxelib:/tink_macro#1.0.1" into tink_macro/1.0.1/haxelib
|
||||
-lib tink_core
|
||||
-cp ${HAXE_LIBCACHE}/tink_macro/1.0.1/haxelib/src
|
||||
-D tink_macro=1.0.1
|
3
haxe_libraries/tink_priority.hxml
Normal file
3
haxe_libraries/tink_priority.hxml
Normal file
@@ -0,0 +1,3 @@
|
||||
-D tink_priority=0.1.3
|
||||
# @install: lix --silent download "gh://github.com/haxetink/tink_priority#ea736d31dc788aae703a2aa415c25d5b80d0e7d1" into tink_priority/0.1.3/github/ea736d31dc788aae703a2aa415c25d5b80d0e7d1
|
||||
-cp ${HAXE_LIBCACHE}/tink_priority/0.1.3/github/ea736d31dc788aae703a2aa415c25d5b80d0e7d1/src
|
6
haxe_libraries/tink_syntaxhub.hxml
Normal file
6
haxe_libraries/tink_syntaxhub.hxml
Normal file
@@ -0,0 +1,6 @@
|
||||
# @install: lix --silent download "gh://github.com/haxetink/tink_syntaxhub#b6ea4966bbdee4d176ac8dd5d2d8ae3b362b2f86" into tink_syntaxhub/0.6.0/github/b6ea4966bbdee4d176ac8dd5d2d8ae3b362b2f86
|
||||
-lib tink_macro
|
||||
-lib tink_priority
|
||||
-cp ${HAXE_LIBCACHE}/tink_syntaxhub/0.6.0/github/b6ea4966bbdee4d176ac8dd5d2d8ae3b362b2f86/src
|
||||
-D tink_syntaxhub=0.6.0
|
||||
--macro tink.SyntaxHub.use()
|
4
haxe_libraries/tink_typecrawler.hxml
Normal file
4
haxe_libraries/tink_typecrawler.hxml
Normal file
@@ -0,0 +1,4 @@
|
||||
# @install: lix --silent download "haxelib:/tink_typecrawler#0.7.0" into tink_typecrawler/0.7.0/haxelib
|
||||
-lib tink_macro
|
||||
-cp ${HAXE_LIBCACHE}/tink_typecrawler/0.7.0/haxelib/src
|
||||
-D tink_typecrawler=0.7.0
|
3
haxe_libraries/uuid.hxml
Normal file
3
haxe_libraries/uuid.hxml
Normal file
@@ -0,0 +1,3 @@
|
||||
# @install: lix --silent download "haxelib:/uuid#2.4.1" into uuid/2.4.1/haxelib
|
||||
-cp ${HAXE_LIBCACHE}/uuid/2.4.1/haxelib/src
|
||||
-D uuid=2.4.1
|
BIN
icons/icon-48.png
Normal file
BIN
icons/icon-48.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 225 B |
34
manifest.json
Normal file
34
manifest.json
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
|
||||
"manifest_version": 2,
|
||||
"name": "pixabay-sourcer",
|
||||
"version": "0.0",
|
||||
|
||||
"description": "",
|
||||
|
||||
"icons": {
|
||||
"48": "icons/icon-48.png"
|
||||
},
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": ["https://pixabay.com/photos/*/"],
|
||||
"js": ["bin/browser-polyfill.js", "bin/main.js"]
|
||||
}
|
||||
],
|
||||
"background": {
|
||||
"scripts": [
|
||||
"bin/browser-polyfill.js",
|
||||
"bin/background.js"
|
||||
]
|
||||
},
|
||||
"browser_specific_settings": {
|
||||
"gecko": {
|
||||
"id": "{0d44525b-9803-4630-917d-585c3b538fcb}"
|
||||
}
|
||||
},
|
||||
"permissions": [
|
||||
"<all_urls>",
|
||||
"storage",
|
||||
"downloads"
|
||||
]
|
||||
}
|
82
package-lock.json
generated
Normal file
82
package-lock.json
generated
Normal file
@@ -0,0 +1,82 @@
|
||||
{
|
||||
"name": "template",
|
||||
"version": "0.0.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "template",
|
||||
"version": "0.0.0",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"@types/webextension-polyfill": "^0.10.0",
|
||||
"webextension-polyfill": "^0.10.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"dts2hx": "^0.19.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/webextension-polyfill": {
|
||||
"version": "0.10.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/webextension-polyfill/-/webextension-polyfill-0.10.0.tgz",
|
||||
"integrity": "sha512-If4EcaHzYTqcbNMp/FdReVdRmLL/Te42ivnJII551bYjhX19bWem5m14FERCqdJA732OloGuxCRvLBvcMGsn4A=="
|
||||
},
|
||||
"node_modules/dts2hx": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/dts2hx/-/dts2hx-0.19.2.tgz",
|
||||
"integrity": "sha512-1+X3kOB941APt/O6b5jX9+XMefRPqvFk4fvGDHPLIbuYdIAjNwcX3XOuZJ9fYtUD7Odn4ACPfK2ql2HWaFrLrg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"typescript": "3.7.4"
|
||||
},
|
||||
"bin": {
|
||||
"dts2hx": "cli.js"
|
||||
}
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "3.7.4",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.4.tgz",
|
||||
"integrity": "sha512-A25xv5XCtarLwXpcDNZzCGvW2D1S3/bACratYBx2sax8PefsFhlYmkQicKHvpYflFS8if4zne5zT5kpJ7pzuvw==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/webextension-polyfill": {
|
||||
"version": "0.10.0",
|
||||
"resolved": "https://registry.npmjs.org/webextension-polyfill/-/webextension-polyfill-0.10.0.tgz",
|
||||
"integrity": "sha512-c5s35LgVa5tFaHhrZDnr3FpQpjj1BB+RXhLTYUxGqBVN460HkbM8TBtEqdXWbpTKfzwCcjAZVF7zXCYSKtcp9g=="
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/webextension-polyfill": {
|
||||
"version": "0.10.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/webextension-polyfill/-/webextension-polyfill-0.10.0.tgz",
|
||||
"integrity": "sha512-If4EcaHzYTqcbNMp/FdReVdRmLL/Te42ivnJII551bYjhX19bWem5m14FERCqdJA732OloGuxCRvLBvcMGsn4A=="
|
||||
},
|
||||
"dts2hx": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/dts2hx/-/dts2hx-0.19.2.tgz",
|
||||
"integrity": "sha512-1+X3kOB941APt/O6b5jX9+XMefRPqvFk4fvGDHPLIbuYdIAjNwcX3XOuZJ9fYtUD7Odn4ACPfK2ql2HWaFrLrg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"typescript": "3.7.4"
|
||||
}
|
||||
},
|
||||
"typescript": {
|
||||
"version": "3.7.4",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.4.tgz",
|
||||
"integrity": "sha512-A25xv5XCtarLwXpcDNZzCGvW2D1S3/bACratYBx2sax8PefsFhlYmkQicKHvpYflFS8if4zne5zT5kpJ7pzuvw==",
|
||||
"dev": true
|
||||
},
|
||||
"webextension-polyfill": {
|
||||
"version": "0.10.0",
|
||||
"resolved": "https://registry.npmjs.org/webextension-polyfill/-/webextension-polyfill-0.10.0.tgz",
|
||||
"integrity": "sha512-c5s35LgVa5tFaHhrZDnr3FpQpjj1BB+RXhLTYUxGqBVN460HkbM8TBtEqdXWbpTKfzwCcjAZVF7zXCYSKtcp9g=="
|
||||
}
|
||||
}
|
||||
}
|
16
package.json
Normal file
16
package.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "template",
|
||||
"version": "0.0.0",
|
||||
"description": "A Firefox extension made with Kisslang",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"postinstall": "dts2hx --all --noLibWrap"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/webextension-polyfill": "^0.10.0",
|
||||
"webextension-polyfill": "^0.10.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"dts2hx": "^0.19.0"
|
||||
}
|
||||
}
|
13
src/pixabay_sourcer/Background.hx
Normal file
13
src/pixabay_sourcer/Background.hx
Normal file
@@ -0,0 +1,13 @@
|
||||
package pixabay_sourcer;
|
||||
|
||||
import kiss.Prelude;
|
||||
import kiss_firefox.API;
|
||||
import haxe.Constraints;
|
||||
import pixabay_sourcer.Message;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class Background {
|
||||
static function main() {
|
||||
_main();
|
||||
}
|
||||
}
|
9
src/pixabay_sourcer/Background.kiss
Normal file
9
src/pixabay_sourcer/Background.kiss
Normal file
@@ -0,0 +1,9 @@
|
||||
(function _main []
|
||||
(API.browser.runtime.onMessage.addListener ->[:Message message sender sendResponse]
|
||||
(let [:Function sendResponse sendResponse]
|
||||
(case message
|
||||
((object type "download" data [url])
|
||||
// TODO awaitLet the DownloadItem and send a nativemessage with the path and credit info
|
||||
(API.browser.downloads.download (objectWith [saveAs true] url)))
|
||||
(never otherwise))
|
||||
true)))
|
7
src/pixabay_sourcer/Main.hx
Normal file
7
src/pixabay_sourcer/Main.hx
Normal file
@@ -0,0 +1,7 @@
|
||||
package pixabay_sourcer;
|
||||
|
||||
class Main {
|
||||
static function main() {
|
||||
Main_.main();
|
||||
}
|
||||
}
|
50
src/pixabay_sourcer/Main_.kiss
Normal file
50
src/pixabay_sourcer/Main_.kiss
Normal file
@@ -0,0 +1,50 @@
|
||||
(import kiss_firefox.API)
|
||||
(import js.lib.Promise)
|
||||
(importAs js.html.XMLHttpRequest XHR)
|
||||
(import pixabay_sourcer.Message)
|
||||
(var :Dynamic document js.Lib.global.document)
|
||||
(var :Dynamic window js.Lib.global.window)
|
||||
|
||||
(var PIXABAY_PUBLIC_KEY "24159230-ce68ffe06827131f3f991f4f6")
|
||||
(var API_URL "https://pixabay.com/api/")
|
||||
|
||||
(function syncedStorage []
|
||||
(API.browser.storage.sync.get (object queries (new Map<String,Dynamic>))))
|
||||
|
||||
(function queryId [:String id :Map<String,Dynamic> cache]
|
||||
(let [request (new XHR)
|
||||
apiQuery "${API_URL}?key=${PIXABAY_PUBLIC_KEY}&id=$id"]
|
||||
(request.open "GET" apiQuery)
|
||||
(request.addEventListener "readystatechange"
|
||||
->:Void
|
||||
(cond
|
||||
((and (= request.readyState 4) (= request.status 200))
|
||||
(let [data (haxe.Json.parse request.responseText)]
|
||||
(dictSet cache id data)
|
||||
(API.browser.storage.sync.set (object queries cache))
|
||||
(handleInfo data)))
|
||||
((= request.readyState 4)
|
||||
// TODO report failure
|
||||
)))
|
||||
(request.send)))
|
||||
|
||||
(function handleInfo [:Dynamic info]
|
||||
(API.browser.runtime.sendMessage (object type "download" data [.largeImageURL (first info.hits)])))
|
||||
|
||||
(window.addEventListener "load"
|
||||
->:Void
|
||||
(awaitLet [storage (syncedStorage)]
|
||||
(let [:Map<String,Dynamic> cachedResults (dictGet storage "queries")
|
||||
:String url window.location.href
|
||||
parts (url.split "/")
|
||||
_ (parts.pop)
|
||||
titleAndId (parts.pop)
|
||||
id (.pop (titleAndId.split "-"))
|
||||
sourceLink (document.createElement "a")]
|
||||
(set sourceLink.innerHTML "Source this image")
|
||||
(sourceLink.addEventListener "click"
|
||||
->:Void
|
||||
(ifLet [cachedInfo (dictGet cachedResults id)]
|
||||
(handleInfo cachedInfo)
|
||||
(queryId id cachedResults)))
|
||||
(document.body.prepend sourceLink))))
|
6
src/pixabay_sourcer/Message.hx
Normal file
6
src/pixabay_sourcer/Message.hx
Normal file
@@ -0,0 +1,6 @@
|
||||
package pixabay_sourcer;
|
||||
|
||||
typedef Message = {
|
||||
type:String,
|
||||
data:Array<String>
|
||||
};
|
Reference in New Issue
Block a user