mirror of
https://github.com/slynn1324/tinypin.git
synced 2026-01-23 02:25:08 +00:00
Merge pull request #4 from ryanfiller/master
create firefox-extension, replace all chrome.func with browser.func
This commit is contained in:
commit
62a61aed72
10 changed files with 7877 additions and 0 deletions
80
firefox-extension/background.js
Normal file
80
firefox-extension/background.js
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/**
|
||||
* Returns a handler which will open a new window when activated.
|
||||
*/
|
||||
function getClickHandler() {
|
||||
return function(info, tab) {
|
||||
|
||||
if ( !info.srcUrl.startsWith('http') ){
|
||||
window.alert("Image source is not a URL.");
|
||||
return;
|
||||
}
|
||||
|
||||
var w = 700;
|
||||
var h = 800;
|
||||
var left = (screen.width/2)-(w/2);
|
||||
var top = (screen.height/2)-(h/2);
|
||||
|
||||
let s = "";
|
||||
if ( info.linkUrl ){
|
||||
s = info.linkUrl;
|
||||
|
||||
// strip the google images redirect
|
||||
if ( s.startsWith("https://www.google.com/url?") ){
|
||||
let parts = s.split("?");
|
||||
|
||||
if ( parts.length == 2 ){
|
||||
|
||||
let params = parts[1].split("&");
|
||||
|
||||
for( let i = 0; i < params.length; ++i ){
|
||||
let kv = params[i].split("=");
|
||||
|
||||
if ( kv.length == 2 ){
|
||||
if ( kv[0] == "url" ){
|
||||
s = decodeURIComponent(kv[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s = encodeURIComponent(s);
|
||||
|
||||
} else {
|
||||
s = encodeURIComponent(info.pageUrl);
|
||||
}
|
||||
|
||||
|
||||
|
||||
var q = "i=" + encodeURIComponent(info.srcUrl) + "&s=" + s;
|
||||
|
||||
|
||||
browser.storage.sync.get({
|
||||
server: 'http://localhost:3000'
|
||||
}, function(items){
|
||||
let server = items.server;
|
||||
|
||||
if ( !server.endsWith('/') ){
|
||||
server += '/';
|
||||
}
|
||||
|
||||
var url = server + 'addpin.html#' + q;
|
||||
|
||||
// Create a new window to the info page.
|
||||
// browser.windows.create({ url: url, width: 520, height: 660 });
|
||||
browser.windows.create({ url: url, width: w, height: h, left: left, top: top, type: 'popup' });
|
||||
});
|
||||
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a context menu which will only show up for images.
|
||||
*/
|
||||
browser.contextMenus.create({
|
||||
"title" : "add to tinypin",
|
||||
"type" : "normal",
|
||||
"contexts" : ["image"],
|
||||
"onclick" : getClickHandler()
|
||||
});
|
||||
7704
firefox-extension/bulma-custom.css
Normal file
7704
firefox-extension/bulma-custom.css
Normal file
File diff suppressed because it is too large
Load diff
BIN
firefox-extension/icon128-blue.png
Normal file
BIN
firefox-extension/icon128-blue.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.7 KiB |
BIN
firefox-extension/icon128.png
Normal file
BIN
firefox-extension/icon128.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
BIN
firefox-extension/icon16.png
Normal file
BIN
firefox-extension/icon16.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 224 B |
BIN
firefox-extension/icon32.png
Normal file
BIN
firefox-extension/icon32.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 329 B |
BIN
firefox-extension/icon48.png
Normal file
BIN
firefox-extension/icon48.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 536 B |
36
firefox-extension/manifest.json
Normal file
36
firefox-extension/manifest.json
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
"name": "add to tinypin",
|
||||
"version": "1.0.0",
|
||||
"description": "add to tinypin context menu plugin",
|
||||
"manifest_version": 2,
|
||||
"background" : {
|
||||
"scripts": ["background.js"],
|
||||
"persistent": true
|
||||
},
|
||||
"options_ui" : {
|
||||
"page": "options.html",
|
||||
"open_in_tab": false
|
||||
},
|
||||
"permissions" : [
|
||||
"contextMenus",
|
||||
"storage"
|
||||
],
|
||||
"icons": {
|
||||
"16" : "icon16.png",
|
||||
"32" : "icon32.png",
|
||||
"48" : "icon48.png",
|
||||
"128" : "icon128.png"
|
||||
},
|
||||
"browser_action" :{
|
||||
"default_title": "add to tinypin",
|
||||
"default_icon" :{
|
||||
"16": "icon16.png",
|
||||
"32": "icon32.png"
|
||||
}
|
||||
},
|
||||
"browser_specific_settings": {
|
||||
"gecko": {
|
||||
"id": "@slynn1324"
|
||||
}
|
||||
}
|
||||
}
|
||||
32
firefox-extension/options.html
Normal file
32
firefox-extension/options.html
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>tinypin options</title>
|
||||
<link rel="stylesheet" href="./bulma-custom.css" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="secton">
|
||||
|
||||
<div class="content" style="margin: 10px;">
|
||||
|
||||
|
||||
<div class="field">
|
||||
<label class="label">tinypin server url</label>
|
||||
<div class="control">
|
||||
<input class="input" id="server" type="text">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button class="button is-success" id="save">Save</button>
|
||||
<span id="status" style="line-height: 2.5em; color: #3273dc;"></span>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="options.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
25
firefox-extension/options.js
Normal file
25
firefox-extension/options.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
function restoreOptions(){
|
||||
browser.storage.sync.get({
|
||||
server: 'http://localhost:3000'
|
||||
}, function(items){
|
||||
document.getElementById('server').value = items.server;
|
||||
});
|
||||
}
|
||||
|
||||
function saveOptions(){
|
||||
let server = document.getElementById('server').value;
|
||||
|
||||
browser.storage.sync.set({
|
||||
server: server
|
||||
}, function(){
|
||||
let status = document.getElementById('status');
|
||||
status.innerText = 'Options saved.';
|
||||
setTimeout(function(){
|
||||
status.innerText = '';
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
document.addEventListener('DOMContentLoaded', restoreOptions);
|
||||
document.getElementById('save').addEventListener('click', saveOptions);
|
||||
Loading…
Add table
Add a link
Reference in a new issue