Skip to content

Commit

Permalink
0.1.0.37 no download scriptsl ink before change fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rostok committed Oct 26, 2021
1 parent c92cda5 commit e9e5f51
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"short_name": "UbiChr",
"homepage_url": "https://github.com/rostok/ubichr",
"author": "rostok",
"version": "0.1.0.36",
"version": "0.1.0.37",
"description": "Revived Ubiquity for Chrome",
"content_security_policy": "script-src 'self' 'unsafe-eval' https://maps.googleapis.com https://cdnjs.cloudflare.com; object-src 'self'",
"manifest_version": 2,
Expand Down
16 changes: 9 additions & 7 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,15 @@ function insertExampleStub() {
async function saveScripts(instance, changeObj) {
// console.log("saveScripts",instance);
// console.log("saveScripts",changeObj);
if (changeObj.origin=='setValue') return; // save on user input

var customscripts = editor.getValue();
// download link
var a = document.getElementById("download");
var file = new Blob([customscripts], {type: "text/plain"});
a.href = URL.createObjectURL(file);
a.download = "ubichr-custom-scripts-"+(new Date()).toISOString().substr(0,10)+".js";

if (changeObj && changeObj.origin=='setValue') return; // save on user input
if (customscripts.trim()=="") {
console.trace();
if (confirm("Are your sure you want remove all your scripts?")) {
Expand Down Expand Up @@ -114,12 +121,6 @@ async function saveScripts(instance, changeObj) {
$("#info").html("<span style='background-color:red'>"+m+"</span>");
if (l != null) $("a#linerror").click( ()=>{ editor.setCursor({line:l,ch:0}); });
}

// download link
var a = document.getElementById("download");
var file = new Blob([customscripts], {type: "text/plain"});
a.href = URL.createObjectURL(file);
a.download = "ubichr-custom-scripts-"+(new Date()).toISOString().substr(0,10)+".js";
}

function saveCursorPos() {
Expand All @@ -146,6 +147,7 @@ editor = CodeMirror.fromTextArea( document.getElementById("code"), {

editor.on("cursorActivity", saveCursorPos);
editor.on("change", saveScripts);
saveScripts(null, {origin:'setValue'}); // prepare initial download

Object.keys(stubs).forEach( k=> {
var s = $(`<a href=# id='${k}'>${k}</a>`);
Expand Down

0 comments on commit e9e5f51

Please sign in to comment.