1
0
Fork 0

Removed trailing spaces, deleted unused files

This commit is contained in:
Dan Hromada 2014-05-14 09:38:59 +02:00
parent b9509bb7d8
commit a2f73986ac
7 changed files with 48 additions and 154 deletions

View file

@ -1,109 +0,0 @@
// /jquery/1.11.0/jquery.min.js
// /jquery/2.1.0/jquery.min.js
$('#open-popbox').on('click', function() {
$('#include-popbox').removeClass('is-hidden');
})
$('#screen-mask').on('click', function() {
$('#include-popbox').addClass('is-hidden');
});
$('#external-scripts').val("# Uncomment address of script below or type your own (one per line) \n" + "# cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js");
chrome.tabs.getSelected(null, function(tab) {
var cjs = $('#cutomjs'),
tsc = $('textarea[name="editor"]', cjs);
var errorHandler = function() {
cjs.css({
"min-width": "120px",
"min-height": "20px",
"width": "350px",
"height": "80px"
});
cjs.removeClass('pure-g').html('<em><strong>It seems that this page cannot be modified with custom js...</strong><br><br> TIP: Try refresh page</em>');
};
var getConfig = function() {
return {
enable: $('input[name="enable"]').is(':checked'),
include: $('select[name="include"]').val()
};
};
var defaultContent = "/**\r\n Type Your custom JS code ... \r\n tip: you can include and use jQuery \r\n note: do not use // for comments \r\n**/\r\n\r\n";
/**
* Show current domain
*/
chrome.tabs.sendRequest(tab.id, {method: "getHost", reload: false}, function(response) {
console.log(response);
try {
$('input[name="domain"]', cjs).val(response.host);
}
catch(e) {
errorHandler();
}
});
/**
* Fill by local script
*/
chrome.tabs.sendRequest(tab.id, {method: "getCustomJS", reload: false}, function(response) {
var src;
if( response.customjs ) {
src = response.customjs.src ? decodeURI(response.customjs.src) : defaultContent;
if( response.customjs.config ) {
var config = response.customjs.config;
if( config.enable ) {
$('input[name="enable"]').attr('checked', 'checked');
}
if( config.include ) {
$('select[name="include"]', cjs).val(response.customjs.config.include);
}
}
}
tsc.val(src || defaultContent);
});
/**
* Enable on textarea change
*/
tsc.on('change keyup paste', function() {
$('input[name="enable"]', cjs).attr('checked', 'checked');
})
/**
* Save local script
*/
$('input[name="save"]', cjs).on('click', function() {
var src = encodeURI(tsc.val()),
customjs = {
src: src,
config: getConfig()
};
chrome.tabs.sendRequest(tab.id, {method: "setCustomJS", customjs: customjs, reload: true});
window.close();
})
/**
* Remove local script
*/
$('input[name="reset"]', cjs).on('click', function() {
tsc.val(decodeURI(defaultContent));
chrome.tabs.sendRequest(tab.id, {method: "removeCustomJS", reload: true});
window.close();
});
/**
* Init editor
*/
var editor = ace.edit("ace-editor");
editor.setTheme("ace/theme/tomorrow");
editor.getSession().setMode("ace/mode/javascript");
editor.setHighlightActiveLine(false);
editor.setUseWrapMode(false);
});

View file

@ -1,9 +1,9 @@
(function(chrome) {
(function(chrome) {
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
switch(request.method) {
switch(request.method) {
case 'setData':
localStorage['customjs'] = JSON.stringify(request.customjs);
case 'getData':
case 'getData':
var customjs = JSON.parse(localStorage['customjs'] || 'false');
sendResponse({customjs: customjs, host: location.host, protocol: location.protocol});
break;

File diff suppressed because one or more lines are too long

View file

@ -45,7 +45,7 @@
this.el.shareBtn.attr('title', this.title.share);
this.el.draftRemoveLink.attr('title', this.title.draft);
},
include: {
include: {
predefined: [
{
name: 'jQuery 1.11.0',
@ -81,11 +81,11 @@
data: {
private: {},
global: {}
},
},
MODE: {
private: 1,
global: 2,
},
},
setMode: function(mode) {
if( mode === this.MODE.private ) {
this.key = popup.key + "-" + popup.protocol + "//" + popup.host;
@ -95,13 +95,13 @@
if( mode === this.MODE.global ) {
this.key = popup.key;
this.mode = this.MODE.global;
}
}
},
load: function() {
this.setMode(this.MODE.private);
this._setData(JSON.parse(localStorage.getItem(this.key) || "{}"));
this.setMode(this.MODE.global);
this.setMode(this.MODE.global);
this._setData(JSON.parse(localStorage.getItem(this.key) || "{}"));
},
_getData: function(key) {
@ -120,7 +120,7 @@
}
else {
return storage.data.global;
}
}
}
},
_setData: function(data, key) {
@ -142,7 +142,7 @@
}
}
},
get: function(key) {
get: function(key) {
return this._getData(key);
},
set: function(arg1, arg2) {
@ -186,18 +186,18 @@
if( !response || typeof response.host !== 'string' ) {
popup.error();
return;
}
}
/**
/**
* Create 'hosts select'
*/
popup.host = response.host;
popup.protocol = response.protocol;
popup.protocol = response.protocol;
// Load storage (global, local) IMPORTANT: Must be called first of all storage operations
// Load storage (global, local) IMPORTANT: Must be called first of all storage operations
popup.storage.load();
// Set storage to store data accessible from all hosts
popup.storage.setMode(popup.storage.MODE.global);
@ -241,7 +241,7 @@
popup.data.source = popup.data.source.replace('data:text/javascript;base64,', '');
popup.data.source = atob(popup.data.source);
}
// Set storage to store data accessible ONLY from current host
popup.storage.setMode(popup.storage.MODE.private);
@ -264,7 +264,7 @@
source: ''
},
applyData: function(data, notDraft) {
if( data && !notDraft ) {
this.el.draftRemoveLink.removeClass('is-hidden');
}
@ -279,14 +279,14 @@
});
}
// Readable format for 'extra include'
else {
else {
data.config.extra = data.config.extra.replace(';', "\n");
}
// Default value for source
if( !data.source ) {
data.source = popup.editor.defaultValue;
}
}
// Set 'predefined include' value
popup.el.includeSelect.val(data.config.include);
@ -325,7 +325,7 @@
return false;
}
var data = popup.getCurrentData();
var data = popup.getCurrentData();
// Transform source for correct apply
data.config.extra = data.config.extra.replace("\n", ';');
@ -333,7 +333,7 @@
// Send new data to apply
chrome.tabs.sendRequest(popup.tabId, {method: "setData", customjs: data, reload: true});
// Save local copy of data
popup.storage.setMode(popup.storage.MODE.private);
popup.storage.set('data', popup.data);
@ -348,7 +348,7 @@
},
reset: function(e) {
e.preventDefault();
if( confirm('Do you really want all away?') ) {
popup.storage.setMode(popup.storage.MODE.private);
popup.storage.remove();
@ -405,7 +405,7 @@
/**
* Inicialize Ace Editor
* Inicialize Ace Editor
*/
popup.editor.init();
@ -438,12 +438,12 @@
var draftAutoSave = function() {
var draft = popup.getCurrentData(),
source = draft.source;
if( (source || !popup.data.source) && source !== popup.data.source ) {
popup.storage.setMode(popup.storage.MODE.private);
popup.storage.set('draft', draft);
// Auto switch 'enable checkbox' on source edit
if( !popup.el.enableCheck.hasClass('not-auto-change') ) {
popup.el.enableCheck.prop('checked', true);
@ -521,6 +521,6 @@
*/
popup.el.draftRemoveLink.on('click', popup.removeDraft);
})(jQuery);

View file

@ -8,9 +8,9 @@
var customjs = localStorage['customjs'];
if( customjs ) {
try {
customjs = JSON.parse(customjs);
customjs = JSON.parse(customjs);
}
catch(e) {
catch(e) {
// Backward compatibility (version >1)
customjs = {
source: customjs,
@ -21,8 +21,8 @@
}
};
localStorage['customjs'] = JSON.stringify(customjs);
}
}
if( customjs.config.enable ) {
// Predefined include
@ -30,7 +30,7 @@
injectScript('https://ajax.googleapis.com/ajax/libs' + customjs.config.include);
}
// Extra include
// Extra include
var extra = (customjs.config.extra || '').split(';');
extra.forEach(function(line) {
if( line.substr(0, 1) !== '#' ) {
@ -39,13 +39,13 @@
});
// Script
if( customjs.source || customjs.src ) {
if( customjs.source || customjs.src ) {
setTimeout(function() {
// Backward compatibility (version 1)
if( customjs.src ) {
customjs.source = 'data:text/javascript,' + customjs.src;
}
injectScript(customjs.source, 'body');
}, 250);
}

View file

@ -11,18 +11,22 @@
"tabs"
],
"tabs": {},
"icons": { "128": "img/icon_128.png" },
"content_security_policy": "script-src 'self' https://*.googleapis.com; object-src 'self'",
"content_scripts": [{
//"all_frames": true,
"matches": ["<all_urls>"],
"js": ["lib/api.js"]
}, {
"all_frames": true,
"matches": ["<all_urls>"],
"js": ["lib/run.js"]
}],
}],
"browser_action": {
"default_icon": "img/icon.png",

View file

@ -2,20 +2,20 @@
<html>
<head>
<title>Custom JavaScript</title>
<link href="css/pure/0.4.2/base-min.css" rel="stylesheet">
<link href="css/pure/0.4.2/grids-nr-min.css" rel="stylesheet">
<link href="css/pure/0.4.2/forms-nr-min.css" rel="stylesheet">
<link href="css/pure/0.4.2/buttons-min.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" src="lib/ace/ace.js" charset="utf-8"></script>
</head>
<body>
<div class="customjs" id="customjs">
<div class="customjs" id="customjs">
<form action="" method="post" accept-charset="utf-8" id="popup-form" class="pure-form">
<div class="pure-g host">
<div class="pure-u-3-5 host__name">
<select id="host" name="host"></select>
@ -23,7 +23,7 @@
</div>
<div class="pure-u-2-5 host__enable">
<label for="enable">
enable <em class="blue-text">cjs</em> for this host
enable <em class="blue-text">cjs</em> for this host
<input id="enable" name="enable" type="checkbox">
</label>
</div>
@ -37,8 +37,8 @@
<div class="pure-u-7-8 include">
<div class="include__body">
You can inject
<a href="#" id="open-popbox">your own external scripts</a> or
You can inject
<a href="#" id="open-popbox">your own external scripts</a> or
<label for="include">predefined one:</label>
<select id="include" name="include">
<option value=""> ---- nothing ---- </option>
@ -74,7 +74,7 @@
<p class="red-text">It seems that this page cannot be modified with me..</p>
<span>tip: Try refresh page</span>
</div><!-- .error -->
</div>
</div>
<script src="lib/popup.js"></script>
</body>
</html>