Skip to content

Commit

Permalink
Alt+S switch
Browse files Browse the repository at this point in the history
  • Loading branch information
SteakOverCooked authored and SteakOverCooked committed Jan 30, 2018
1 parent deb7598 commit 8431c8f
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 11 deletions.
18 changes: 18 additions & 0 deletions js/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
switch(message.type) {
case "console.log":
console.log(message.obj);
break;
}
return true;
});

chrome.runtime.onInstalled.addListener(function(details){
if(details.reason == "install"){
//call a function to handle a first install
console.log("onInstalled: Thank you!");
}else if(details.reason == "update"){
//call a function to handle an update
console.log("new version available.");
}
});
31 changes: 31 additions & 0 deletions js/content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
$(function() {
let id;
let website;

chrome.storage.sync.get('utopian_settings', function(data) {
if (data && data.utopian_settings) {
let utopian = data.utopian_settings;
if (utopian["steemit_id"]) {
id = utopian["steemit_id"].trim();
}
if (utopian["steemit_website"]) {
website = utopian["steemit_website"].trim();
}
}
});
website = website || "steemit.com";

// short cut Alt + S to switch between utopian and steemit
$(document).keydown(function(e) {
if(e.key.toLowerCase() == "s" && e.altKey) {
var url = document.location.href;
if (url.includes("utopian.io")) {
document.location.href = url.replace("utopian.io", website);
} else if (url.includes("steemit.com")) {
document.location.href = url.replace("steemit.com", "utopian.io");
} else if (url.includes("busy.org")) {
document.location.href = url.replace("busy.org", "utopian.io");
}
}
});
})();
26 changes: 16 additions & 10 deletions js/utopian.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ function getVP(id) {
},
complete: function(data) {
logit("API Finished.");
$('img#loading').hide();
}
});
}
Expand All @@ -109,7 +108,6 @@ function getRep(id) {
},
complete: function(data) {
logit("API Finished.");
$('img#loading').hide();
}
});
}
Expand All @@ -120,26 +118,34 @@ document.addEventListener('DOMContentLoaded', function() {
$( "#tabs" ).tabs();
});
// load steem id
chrome.storage.sync.get('steemit_id', function(data) {
if (data != null) {
if ((data.steemit_id != null)) {
let id = data.steemit_id.trim();
chrome.storage.sync.get('utopian_settings', function(data) {
if (data && data.utopian_settings) {
let utopian = data.utopian_settings;
if (utopian["steemit_id"]) {
let id = utopian["steemit_id"].trim();
$('input#steemit_id').val(id);
if (id != '') {
getVP(id);
getRep(id);
}
}
if (utopian["steemit_website"]) {
let website = utopian["steemit_website"].trim();
$('select#steemit_website').val(website);
}
}
});
$('button#save_id_btn').click(function() {
let id = $('input#steemit_id').val().trim();
let website = $('select#steemit_website').val();
let utopian = {};
utopian['steemit_id'] = id;
utopian['steemit_website'] = website;
chrome.storage.sync.set({
steemit_id: id
utopian_settings: utopian
}, function() {
alert('Saved.');
});
if (id != '') {
alert('ID Saved.');
}
});
// about
let manifest = chrome.runtime.getManifest();
Expand Down
13 changes: 12 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Utopian Moderator & Supervisor",
"short_name": "Utopian-IO",
"default_locale": "en",
"version": "0.0.1",
"version": "0.0.2",
"browser_action": {
"default_icon": "icon.png",
"default_title": "Utopian Moderator & Supervisor",
Expand All @@ -24,6 +24,17 @@
"css/*",
"bs/*"
],
"background": {
"scripts": ["js/background.js"]
},
"content_scripts": [{
"matches": ["<all_urls>"],
"js":[
"js/jquery-3.2.1.min.js",
"js/content.js"
],
"run_at":"document_start"
}],
"permissions": [
"activeTab",
"storage",
Expand Down
7 changes: 7 additions & 0 deletions utopian-ext-main.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@
</div>
<div id="tabs-3">
<p><h4>Your SteemId ID: </h4><input type='text' class='form-control' id='steemit_id' name='steemit_id' value=''></p>
<p>
<h4>Alt + S: </h4>
<select class='form-control' id='steemit_website' name='steemit_website'>
<option value='steemit.com'>steemit.com</option>
<option value='busy.org'>busy.org</option>
</select>
</p>
<p><button class='form-control' style='width:70px' id='save_id_btn'>Save</button></p>
</div>
<div id="tabs-4">
Expand Down

0 comments on commit 8431c8f

Please sign in to comment.