create firefox-extension, replace all chrome.func with browser.func

This commit is contained in:
ryanfiller 2024-05-16 13:03:11 -05:00
parent fed01f948b
commit 219f6d48b5
10 changed files with 7877 additions and 0 deletions

View 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()
});

File diff suppressed because it is too large Load diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 536 B

View 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"
}
}
}

View 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>

View 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);