1
0
Fork 0

First version

This commit is contained in:
Dan Hromada 2014-05-07 13:56:35 +02:00
parent 7f1b7b9ea8
commit cd8ecb97ed
12 changed files with 290 additions and 0 deletions

11
css/pure/0.4.2/base-min.css vendored Normal file
View file

@ -0,0 +1,11 @@
/*!
Pure v0.4.2
Copyright 2014 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
https://github.com/yui/pure/blob/master/LICENSE.md
*/
/*!
normalize.css v1.1.3 | MIT License | git.io/normalize
Copyright (c) Nicolas Gallagher and Jonathan Neal
*/
/*! normalize.css v1.1.3 | MIT License | git.io/normalize */article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary{display:block}audio,canvas,video{display:inline-block;*display:inline;*zoom:1}audio:not([controls]){display:none;height:0}[hidden]{display:none}html{font-size:100%;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}html,button,input,select,textarea{font-family:sans-serif}body{margin:0}a:focus{outline:thin dotted}a:active,a:hover{outline:0}h1{font-size:2em;margin:.67em 0}h2{font-size:1.5em;margin:.83em 0}h3{font-size:1.17em;margin:1em 0}h4{font-size:1em;margin:1.33em 0}h5{font-size:.83em;margin:1.67em 0}h6{font-size:.67em;margin:2.33em 0}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:700}blockquote{margin:1em 40px}dfn{font-style:italic}hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0}mark{background:#ff0;color:#000}p,pre{margin:1em 0}code,kbd,pre,samp{font-family:monospace,serif;_font-family:'courier new',monospace;font-size:1em}pre{white-space:pre;white-space:pre-wrap;word-wrap:break-word}q{quotes:none}q:before,q:after{content:'';content:none}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-.5em}sub{bottom:-.25em}dl,menu,ol,ul{margin:1em 0}dd{margin:0 0 0 40px}menu,ol,ul{padding:0 0 0 40px}nav ul,nav ol{list-style:none;list-style-image:none}img{border:0;-ms-interpolation-mode:bicubic}svg:not(:root){overflow:hidden}figure{margin:0}form{margin:0}fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em}legend{border:0;padding:0;white-space:normal;*margin-left:-7px}button,input,select,textarea{font-size:100%;margin:0;vertical-align:baseline;*vertical-align:middle}button,input{line-height:normal}button,select{text-transform:none}button,html input[type=button],input[type=reset],input[type=submit]{-webkit-appearance:button;cursor:pointer;*overflow:visible}button[disabled],html input[disabled]{cursor:default}input[type=checkbox],input[type=radio]{box-sizing:border-box;padding:0;*height:13px;*width:13px}input[type=search]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}input[type=search]::-webkit-search-cancel-button,input[type=search]::-webkit-search-decoration{-webkit-appearance:none}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}textarea{overflow:auto;vertical-align:top}table{border-collapse:collapse;border-spacing:0}[hidden]{display:none!important}

7
css/pure/0.4.2/buttons-min.css vendored Normal file
View file

@ -0,0 +1,7 @@
/*!
Pure v0.4.2
Copyright 2014 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
https://github.com/yui/pure/blob/master/LICENSE.md
*/
.pure-button{display:inline-block;*display:inline;zoom:1;line-height:normal;white-space:nowrap;vertical-align:baseline;text-align:center;cursor:pointer;-webkit-user-drag:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.pure-button::-moz-focus-inner{padding:0;border:0}.pure-button{font-family:inherit;font-size:100%;*font-size:90%;*overflow:visible;padding:.5em 1em;color:#444;color:rgba(0,0,0,.8);*color:#444;border:1px solid #999;border:0 rgba(0,0,0,0);background-color:#E6E6E6;text-decoration:none;border-radius:2px}.pure-button-hover,.pure-button:hover,.pure-button:focus{filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#00000000', endColorstr='#1a000000', GradientType=0);background-image:-webkit-gradient(linear,0 0,0 100%,from(transparent),color-stop(40%,rgba(0,0,0,.05)),to(rgba(0,0,0,.1)));background-image:-webkit-linear-gradient(transparent,rgba(0,0,0,.05) 40%,rgba(0,0,0,.1));background-image:-moz-linear-gradient(top,rgba(0,0,0,.05) 0,rgba(0,0,0,.1));background-image:-o-linear-gradient(transparent,rgba(0,0,0,.05) 40%,rgba(0,0,0,.1));background-image:linear-gradient(transparent,rgba(0,0,0,.05) 40%,rgba(0,0,0,.1))}.pure-button:focus{outline:0}.pure-button-active,.pure-button:active{box-shadow:0 0 0 1px rgba(0,0,0,.15) inset,0 0 6px rgba(0,0,0,.2) inset}.pure-button[disabled],.pure-button-disabled,.pure-button-disabled:hover,.pure-button-disabled:focus,.pure-button-disabled:active{border:0;background-image:none;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);filter:alpha(opacity=40);-khtml-opacity:.4;-moz-opacity:.4;opacity:.4;cursor:not-allowed;box-shadow:none}.pure-button-hidden{display:none}.pure-button::-moz-focus-inner{padding:0;border:0}.pure-button-primary,.pure-button-selected,a.pure-button-primary,a.pure-button-selected{background-color:#0078e7;color:#fff}

7
css/pure/0.4.2/forms-nr-min.css vendored Normal file

File diff suppressed because one or more lines are too long

7
css/pure/0.4.2/grids-nr-min.css vendored Normal file
View file

@ -0,0 +1,7 @@
/*!
Pure v0.4.2
Copyright 2014 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
https://github.com/yui/pure/blob/master/LICENSE.md
*/
.pure-g{letter-spacing:-.31em;*letter-spacing:normal;*word-spacing:-.43em;text-rendering:optimizespeed;font-family:FreeSans,Arimo,"Droid Sans",Helvetica,Arial,sans-serif;display:-webkit-flex;-webkit-flex-flow:row wrap;display:-ms-flexbox;-ms-flex-flow:row wrap}.opera-only :-o-prefocus,.pure-g{word-spacing:-.43em}.pure-u{display:inline-block;*display:inline;zoom:1;letter-spacing:normal;word-spacing:normal;vertical-align:top;text-rendering:auto}.pure-g [class *="pure-u"]{font-family:sans-serif}.pure-u-1,.pure-u-1-1,.pure-u-1-2,.pure-u-1-3,.pure-u-2-3,.pure-u-1-4,.pure-u-3-4,.pure-u-1-5,.pure-u-2-5,.pure-u-3-5,.pure-u-4-5,.pure-u-5-5,.pure-u-1-6,.pure-u-5-6,.pure-u-1-8,.pure-u-3-8,.pure-u-5-8,.pure-u-7-8,.pure-u-1-12,.pure-u-5-12,.pure-u-7-12,.pure-u-11-12,.pure-u-1-24,.pure-u-2-24,.pure-u-3-24,.pure-u-4-24,.pure-u-5-24,.pure-u-6-24,.pure-u-7-24,.pure-u-8-24,.pure-u-9-24,.pure-u-10-24,.pure-u-11-24,.pure-u-12-24,.pure-u-13-24,.pure-u-14-24,.pure-u-15-24,.pure-u-16-24,.pure-u-17-24,.pure-u-18-24,.pure-u-19-24,.pure-u-20-24,.pure-u-21-24,.pure-u-22-24,.pure-u-23-24,.pure-u-24-24{display:inline-block;*display:inline;zoom:1;letter-spacing:normal;word-spacing:normal;vertical-align:top;text-rendering:auto}.pure-u-1-24{width:4.1667%;*width:4.1357%}.pure-u-1-12,.pure-u-2-24{width:8.3333%;*width:8.3023%}.pure-u-1-8,.pure-u-3-24{width:12.5%;*width:12.469%}.pure-u-1-6,.pure-u-4-24{width:16.6667%;*width:16.6357%}.pure-u-1-5{width:20%;*width:19.969%}.pure-u-5-24{width:20.8333%;*width:20.8023%}.pure-u-1-4,.pure-u-6-24{width:25%;*width:24.969%}.pure-u-7-24{width:29.1667%;*width:29.1357%}.pure-u-1-3,.pure-u-8-24{width:33.3333%;*width:33.3023%}.pure-u-3-8,.pure-u-9-24{width:37.5%;*width:37.469%}.pure-u-2-5{width:40%;*width:39.969%}.pure-u-5-12,.pure-u-10-24{width:41.6667%;*width:41.6357%}.pure-u-11-24{width:45.8333%;*width:45.8023%}.pure-u-1-2,.pure-u-12-24{width:50%;*width:49.969%}.pure-u-13-24{width:54.1667%;*width:54.1357%}.pure-u-7-12,.pure-u-14-24{width:58.3333%;*width:58.3023%}.pure-u-3-5{width:60%;*width:59.969%}.pure-u-5-8,.pure-u-15-24{width:62.5%;*width:62.469%}.pure-u-2-3,.pure-u-16-24{width:66.6667%;*width:66.6357%}.pure-u-17-24{width:70.8333%;*width:70.8023%}.pure-u-3-4,.pure-u-18-24{width:75%;*width:74.969%}.pure-u-19-24{width:79.1667%;*width:79.1357%}.pure-u-4-5{width:80%;*width:79.969%}.pure-u-5-6,.pure-u-20-24{width:83.3333%;*width:83.3023%}.pure-u-7-8,.pure-u-21-24{width:87.5%;*width:87.469%}.pure-u-11-12,.pure-u-22-24{width:91.6667%;*width:91.6357%}.pure-u-23-24{width:95.8333%;*width:95.8023%}.pure-u-1,.pure-u-1-1,.pure-u-5-5,.pure-u-24-24{width:100%}

32
css/style.css Normal file
View file

@ -0,0 +1,32 @@
.cutomjs {
min-width: 500px;
min-height: 500px;
padding: 25px;
}
textarea {
width: 100%;
height: 400px;
font-size: 12px;
color: #454545;
}
label {
line-height: 37px;
font-size: 80%;
}
input[type="checkbox"] {
position: relative;
top: 2px;
}
em {
font-style: italic;
color: #0f14f3;
}
.text-right {
text-align: right;
}

BIN
img/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
img/icon_128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

1
lib/behave.js Normal file

File diff suppressed because one or more lines are too long

96
lib/popup.js Normal file
View file

@ -0,0 +1,96 @@
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();
})
/**
* Set textarea as behave
*/
var editor = new Behave({
textarea: tsc[0],
tabSize: 3
});
});

54
lib/script.js Normal file
View file

@ -0,0 +1,54 @@
var customjs = localStorage['customjs'];
if( customjs ) {
try {
customjs = JSON.parse(customjs);
}
catch(e) { // Old version
customjs = {
src: customjs,
config: {
enable: true,
include: ''
}
};
localStorage['customjs'] = JSON.stringify(customjs);
}
if( customjs.config.enable ) {
if( customjs.config.include ) {
var jquery = document.createElement('script');
jquery.src = 'https://ajax.googleapis.com/ajax/libs' + customjs.config.include;
document.head.appendChild(jquery);
}
if( customjs.src ) {
var cusomscript = document.createElement('script');
cusomscript.src = 'data:text/javascript,' + decodeURI(customjs.src);
setTimeout(function() {
document.body.appendChild(cusomscript);
}, 250);
}
}
}
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
switch(request.method) {
case 'getHost':
sendResponse({host: location.host});
break;
case 'setCustomJS':
localStorage['customjs'] = JSON.stringify(request.customjs);
case 'getCustomJS':
var customjs = JSON.parse(localStorage['customjs'] || '{}');
sendResponse({customjs: customjs});
break;
case 'removeCustomJS':
delete localStorage['customjs'];
break;
default:
sendResponse({src: '', config: {}});
}
if( request.reload ) {
window.location.reload();
}
});

27
manifest.json Normal file
View file

@ -0,0 +1,27 @@
{
"manifest_version": 2,
"name": "Custom JavaScript for websites ",
"description": "Run custom JavaScript on any website.",
"version": "1.1.3",
"permissions": [
"http://*/",
"https://*/",
"tabs"
],
"icons": { "128": "img/icon_128.png" },
"content_security_policy": "script-src 'self' https://*.googleapis.com; object-src 'self'",
"content_scripts": [{
"matches": ["<all_urls>"],
"js": ["lib/script.js"]
}],
"browser_action": {
"default_icon": "img/icon.png",
"default_popup": "popup.html"
}
}

48
popup.html Normal file
View file

@ -0,0 +1,48 @@
<!doctype html>
<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 type="text/javascript" src="lib/behave.js"></script>
</head>
<body>
<div class="cutomjs pure-g" id="cutomjs">
<form action="" method="post" accept-charset="utf-8" class="pure-form">
<div class="about pure-u-2-5">
<input type="text" name="domain" value="example.com" readonly="readonly">
</div>
<div class="enable pure-u-3-5 text-right">
<label for="enable">
enable <em>cjs</em> for this domain <input id="enable" name="enable" type="checkbox">
</label>
</div>
<div class="pure-u-1"></div>
<div class="editor pure-u-1">
<textarea id="editor" name="editor"></textarea>
</div>
<div class="pure-u-1"></div>
<div class="control pure-u-3-5">
<input type="submit" name="save" value="save" class="pure-button pure-button-primary">
<input type="submit" name="reset" value="reset" class="pure-button">
</div>
<div class="include pure-u-2-5 text-right">
<label for="include">
include <select name="include" id="include">
<option value=""> ---- nothing ---- </option>
<option value="/jquery/1.11.0/jquery.min.js">jQuery 1.11.0</option>
<option value="/jquery/2.1.0/jquery.min.js">jQuery 2.1.0</option>
</select>
</label>
</div>
</form>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="lib/popup.js"></script>
</body>
</html>