Permalink
Browse files

Russian language via :lang of CSS 3;

Minor fixes;
Auto-format option.
  • Loading branch information...
1 parent e02025c commit 20af6e30b9bbd80e979aaf43a82078e47cecc85d @Dither committed Mar 24, 2011
Showing with 242 additions and 302 deletions.
  1. +15 −3 README.txt
  2. +2 −1 config.xml
  3. +26 −2 css/options.css
  4. +33 −82 css/popup.css
  5. +40 −0 includes/common.js
  6. +58 −91 includes/injected.js
  7. +3 −3 index.html
  8. +44 −23 options.html
  9. +21 −97 popup.html
View
18 README.txt
@@ -1,10 +1,22 @@
Readable JavaScript for Opera
=============
-Extension for auto-formatting JavaScript code.
+Extension for auto-formatting of JavaScript code.
-It is triggered by clicking yellow popup which appears on top of a page
-for files with .js extension in their URL or by the toolbar button.
+Extension for auto-formatting of JavaScript code. It is triggered by clicking
+yellow popup on top of page if file has .js extension in its URL. Also you can
+call simple formatter using toolbar button.
+
+From the preferences page it is possible to:
+ - disable confirmation popup and auto-format all javascripts;
+ - toggle JavaScript formatter button in toolbar (effective after Opera restart);
+ - set carry over opening braces to their own lines;
+ - set preservation of empty lines in code;
+ - toggle packer detection (supported packers: P_A_C_K_E_R, escaped bookmarklets, javascriptobfuscator.com);
+ - set method for array indentation;
+ - set number of indentation spaces or indentation using Tab character;
+ - toggle syntax highlighting;
+ - toggle debug output for showing parsing progress status in the console.
This extension supports optional syntax highlighting based on Google's PrettyPrint
parser but it is very slow and sometimes hurts my eyes with strange guessing
View
3 config.xml
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
-<widget xmlns="http://www.w3.org/ns/widgets" id="extensions:readable-javascript" version="1.0">
+<widget xmlns="http://www.w3.org/ns/widgets" id="extensions:readable-javascript" version="1.1">
<name>Readable JavaScript</name>
<author href="http://my.opera.com/DitherSky/blog/">Dither</author>
<description>Extension for auto-formatting and colorizing JavaScript code. Triggered by files with .js extension in their URL or by toolbar button.</description>
@@ -11,6 +11,7 @@
<preference name="debug_output" value="false"/>
<preference name="enable_coloring" value="false"/>
<preference name="enable_button" value="true"/>
+ <preference name="autoparse_js" value="false"/>
<preference name="indent_char" value=" "/>
<icon src="icons/icon.png"/>
<!--<credit>icon.png by Iconshock - non-comercial free license.</credit> -->
View
28 css/options.css
@@ -1,4 +1,4 @@
-html {
+html {
background: rgb(255,255,255) -o-linear-gradient(rgb(212,212,212),rgb(255,255,255)) repeat-x;
}
@@ -62,11 +62,16 @@ fieldset {
padding: 10px 20px;
}
-fieldset label {
+fieldset label, fieldset legend {
margin-left: 0px;
font-size: 16px;
}
+#indent_size input[type=radio] {
+ margin-right: 0px !important;
+ font-size: 16px;
+}
+
fieldset *:disabled {
opacity: 0.5;
}
@@ -144,3 +149,22 @@ fieldset input[type=radio]:disabled, fieldset input[type=checkbox]:disabled {
background: #fff;
border-color: rgba(80,80,130,0.5);
}
+
+#label_preferences:lang(ru){content: 'Настройки';/*Preferences*/}
+#widget_name:lang(ru){content: 'Читабельный JavaScript v1.1'; /*Readable JavaScript v1.1*/}
+#enable_button_label:lang(ru){content: 'Кнопка на панели задач (после перезапуска браузера)'; /*Toolbar button (browser restart needed)*/}
+#autoparse_js_label:lang(ru){content: 'Форматирование скриптов без подтверждения'; /*Disable confirmation popup for files (auto-parse)*/}
+#indent_size_label:lang(ru){content: 'Отступы'; /*Indentation:*/}
+#braces_on_own_line_label:lang(ru){content: 'Открывающие фигурные скобки с новой строки'; /*Braces on own line*/}
+#preserve_newlines_label:lang(ru){content: 'Сохранять пустые строки'; /*Preserve empty lines*/}
+#detect_packers_label:lang(ru){content: 'Определять упаковщик'; /*Detect packers*/}
+#keep_array_indentation_label:lang(ru){content: 'Сохранять отступы у массивов'; /*Keep array indentation*/}
+#enable_coloring_label:lang(ru){content: 'Подсветка синтаксиса (очень медленно)'; /*Syntax highlighting (very slow)*/}
+#debug_output_label:lang(ru){content: 'Отладочная информация'; /*Debug output*/}
+#footer_text:lang(ru){content: 'Сделано для браузера Opera'; /*Powered by the Opera Browser*/}
+#indent_size_tab_label:lang(ru){content: 'табуляция';/*tab character*/}
+#indent_size_two_label:lang(ru){content: 'два пробела';/*2 spaces*/}
+#indent_size_three_label:lang(ru){content: 'три пробела';/*3 spaces*/}
+#indent_size_four_label:lang(ru){content: 'четыре пробела';/*4 spaces*/}
+#indent_size_eight_label:lang(ru){content: 'восемь пробелов';/*8 spaces*/}
+
View
115 css/popup.css
@@ -1,88 +1,39 @@
-/**
- * CSS for Clippy mode
- */
-
-#jsb4c-clippy {
- background-color: transparent;
- background-repeat: no-repeat;
- width: 223px;
- height: 228px;
- position: fixed;
- right: -300px;
- bottom: 10px;
-
- -o-transition-property: right;
- -o-transition-duration: 0.5s;
-}
-
-#jsb4c-clippy.jsb4c-visible {
- right: 10px;
-}
-
-#jsb4c-clippy #jsb4c-yes, #jsb4c-clippy #jsb4c-no {
- font-size: 13px;
- font-family: "Arial", sans-serif;
- display: block;
- float: left;
- margin-top: 98px;
- padding-top: 3px;
- color: black;
- text-decoration: none;
- text-align: center;
- cursor: pointer;
+* {
+margin: 0 0 0 0;
+padding: 0 0 0 0;
}
-
-#jsb4c-clippy #jsb4c-yes {
- margin-left: 10px;
- width: 90px;
+body {
+font-size:14px;
+font-family: "arial", "helvetica", sans-serif;
+overflow:hidden;
+padding-right:4px;
+padding-top:4px;
}
-
-#jsb4c-clippy #jsb4c-no {
- margin-left: 13px;
- width: 95px;
+fieldset{
+border: none;
}
-
-/**
- * CSS for bar mode
- */
-
-#jsb4c-bar {
- height: 22px;
- position: fixed;
- top: -40px;
- left: 0;
- width: 100%;
-
- cursor: pointer;
-
- background-image: -o-linear-gradient(
- top, rgb(250,233,167) 0%, rgb(254,243,197) 100%
- );
- border-bottom: 1px solid #8e8e8e;
-
- -o-transition-property: top;
- -o-transition-duration: 0.5s;
-
- padding-top: 10px;
- padding-left: 10px;
- font-family: "Helvetica", "Arial", sans-serif;
- font-size: 12px;
+textarea {
+font-family: "consolas", "Terminus", "lucida console", "courier new", "courier", monospace;
+font-size: 12px;
}
-
-#jsb4c-bar.jsb4c-visible {
- top: 0;
+button {
+background:#eee;
+padding:3px 5px;
+border-bottom-color:#999;
+border-bottom-style:solid;
+border-bottom-width:1px;
+border-left-color:#ccc;
+border-left-style:solid;
+border-left-width:1px;
+border-right-color:#999;
+border-right-style:solid;
+border-right-width:1px;
+border-top-color:#ccc;
+border-top-style:solid;
+border-top-width:1px;
+cursor:pointer;
+margin-top:2px;
+width:100%
}
-#jsb4c-bar #jsb4c-no {
- display: block;
- height: 32px;
- width: 32px;
- float: right;
- text-indent: -9999px;
-
- margin: -10px 10px 0 0;
-
- background-color: transparent;
- background-repeat: no-repeat;
- background-position: center center;
-}
+#makereadable:lang(ru){content: 'Сделать читабельным';/*Make readable*/}
View
40 includes/common.js
@@ -0,0 +1,40 @@
+function s2b(s) { return s === 'true' ? true : false; }
+
+function trim_comments(str)
+{
+ var lines = str.split('\n'), tmp = '';
+ for (var i = 0; i < lines.length; i++) tmp += lines[i].replace(/([^\x2f]*)\x2f\x2f.*$/, '$1');
+ lines = tmp.split('*/');
+ tmp = '';
+ for (var i = 0; i < lines.length; i++) tmp += lines[i].replace(/(.*)\x2f\x2a(.*)$/g, '$1 ');
+ tmp = tmp.replace(/^\s+/g, '');
+ return tmp;
+}
+
+function unpacker_filter(source)
+{
+ var stripped_source = trim_comments(source);
+ var unpacked = '';
+
+ if (P_A_C_K_E_R.detect(stripped_source)) {
+ unpacked = P_A_C_K_E_R.unpack(stripped_source);
+ if (unpacked !== stripped_source) {
+ return unpacker_filter(unpacked);
+ }
+ }
+
+ if (EscapedBookmarklet.detect(source)) {
+ unpacked = EscapedBookmarklet.unpack(source);
+ if (unpacked !== stripped_source) {
+ return unpacker_filter(unpacked);
+ }
+ }
+
+ if (JavascriptObfuscator.detect(stripped_source)) {
+ unpacked = JavascriptObfuscator.unpack(stripped_source);
+ if (unpacked !== stripped_source) {
+ return unpacker_filter(unpacked);
+ }
+ }
+ return source;
+}
View
149 includes/injected.js
@@ -1,9 +1,15 @@
(function () {
- if (!window.location.href.match(/\.js(?:\?|$)/) || !document || !document.body || document.body.querySelectorAll('*').length !== 1) return;
+ if (!window.location.href.match(/\.js(?:\?|$)/) || typeof document === 'undefined' || !document.body || document.body.querySelectorAll('*').length !== 1) return;
+
+ var storage;
+ if (typeof widget === 'undefined' || typeof widget.preferences === 'undefined') {
+ storage = {'autoparse_js': 'false','enable_button': 'true','indent_size': '4','preserve_newlines':'true','keep_array_indentation':'true','detect_packers':'true','braces_on_own_line':'false','indent_char':' ','debug_output':'false','enable_coloring':'false'}
+ } else { storage = widget.preferences; }
- function s2b(s) { return s === 'true' ? true : false; }
function log(){ if (s2b(storage['debug_output'])) opera.postError(Array.prototype.slice.call(arguments))}
+///////////////////////////////////// STYLES AND TRANSLATION /////////////////////////////////////////
+
var JSREADABLE_STRINGS = (function(locale){ var lang = window.navigator.language.slice(0,2); return locale[lang] || locale["en"];})({
ru: {
hint: "\u0424\u0430\u0439\u043b \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 JavaScript. \u041a\u043b\u0438\u043a\u043d\u0438\u0442\u0435 \u043d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u044e\u0449\u0435\u043c \u043e\u043a\u043e\u0448\u043a\u0435 \u0434\u043b\u044f \u0435\u0433\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0410\u0432\u0442\u043e\u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 ",
@@ -14,14 +20,8 @@
sec: 'sec.',
}
});
-
- var storage = widget.preferences;
- var notification = document.createElement('div'),
- close = document.createElement('a'),
- autoHideInterval,
- secondsTillHide = 12,
- formatConfirmElement;
-
+
+
var cssinfo='/** CSS for bar mode */\
#jsb4c-bar {\
height: 22px;\
@@ -97,62 +97,11 @@ li.L9 { background: #eee }\
.atn { color: #404; }\
.atv { color: #060; }\
}';
+
+//////////////////////////////////////////////////////////////////////////////
- function trim_comments(str)
- {
- var lines = str.split('\n'), tmp = '';
- for (var i = 0; i < lines.length; i++) tmp += lines[i].replace(/([^\x2f]*)\x2f\x2f.*$/, '$1');
- lines = tmp.split('*/');
- tmp = '';
- for (var i = 0; i < lines.length; i++) tmp += lines[i].replace(/(.*)\x2f\x2a(.*)$/g, '$1 ');
- tmp = tmp.replace(/^\s+/g, '');
- return tmp;
- }
-
- function unpacker_filter(source)
- {
-
- if (s2b(storage['detect_packers'])) {
- log('[ReadableJS]: Trying to detect packers...');
-
- var stripped_source = trim_comments(source);
- var unpacked = '';
-
- if (P_A_C_K_E_R.detect(stripped_source)) {
- log('[ReadableJS]: P_A_C_K_E_R detected');
- unpacked = P_A_C_K_E_R.unpack(stripped_source);
- if (unpacked !== stripped_source) {
- return unpacker_filter(unpacked);
- }
- }
-
- if (EscapedBookmarklet.detect(source)) {
- log('[ReadableJS]: Escaped bookmarklet detected');
- unpacked = EscapedBookmarklet.unpack(source);
- if (unpacked !== stripped_source) {
- return unpacker_filter(unpacked);
- }
- }
-
- if (JavascriptObfuscator.detect(stripped_source)) {
- log('[ReadableJS]: JavaScript Obfuscator detected');
- unpacked = JavascriptObfuscator.unpack(stripped_source);
- if (unpacked !== stripped_source) {
- return unpacker_filter(unpacked);
- }
- }
- }
- return source;
- }
-
log('[ReadableJS]: Readable JavaScript extension started');
-
- var css = document.createElement('style');
- css.type = 'text/css';
- css.appendChild(document.createTextNode(cssinfo));
-
- notification.appendChild(css);
-
+
if (s2b(storage['enable_coloring'])) {
document.getElementsByTagName('PRE')[0].className = 'prettyprint';
document.getElementsByTagName('PRE')[0].id = 'javascript'
@@ -162,6 +111,20 @@ li.L9 { background: #eee }\
document.body.appendChild(css1);
}
+ if (s2b(storage['autoparse_js'])) { parseJavaScript(); return; }
+
+ var notification = document.createElement('div'),
+ close = document.createElement('a'),
+ autoHideInterval,
+ secondsTillHide = 12,
+ formatConfirmElement;
+
+ var css = document.createElement('style');
+ css.type = 'text/css';
+ css.appendChild(document.createTextNode(cssinfo));
+
+ notification.appendChild(css);
+
notification.id = 'jsb4c-bar';
close.id = 'jsb4c-close';
@@ -183,39 +146,43 @@ li.L9 { background: #eee }\
}, false);
notification.addEventListener('click', function (event) {
- var code = document.getElementsByTagName('pre')[0];
- log('[ReadableJS]: JavaScript formatting options:\n indent_size = '+ Number(storage['indent_size'],10)+
- '\n indent_char = '+storage['indent_char']+
- '\n preserve_newlines = '+s2b(storage['preserve_newlines'])+
- '\n braces_on_own_line = '+s2b(storage['braces_on_own_line'])+
- '\n keep_array_indentation = '+s2b(storage['keep_array_indentation']));
-
hideNotification();
event.preventDefault();
event.stopPropagation();
- setTimeout(function () {
- log('[ReadableJS]: Formatting JavaScript...');
- code.textContent = make_js_readable(unpacker_filter(code.textContent),
- {
- indent_size: Number(storage['indent_size'],10),
- indent_char: storage['indent_char'],
- preserve_newlines: s2b(storage['preserve_newlines']),
- braces_on_own_line: s2b(storage['braces_on_own_line']),
- keep_array_indentation: s2b(storage['keep_array_indentation']),
- space_after_anon_function: true
- }
- );
- }, 300);
-
- if (s2b(storage['enable_coloring'])) {
+ parseJavaScript();
+ }, false);
+
+ function parseJavaScript() {
+ log('[ReadableJS]: JavaScript formatting options:\n indent_size = '+ Number(storage['indent_size'],10)+
+ '\n indent_char = "'+storage['indent_char']+'"'+
+ '\n preserve_newlines = '+s2b(storage['preserve_newlines'])+
+ '\n braces_on_own_line = '+s2b(storage['braces_on_own_line'])+
+ '\n keep_array_indentation = '+s2b(storage['keep_array_indentation']));
+
+ var code = document.getElementsByTagName('PRE')[0];
setTimeout(function () {
- log('[ReadableJS]: Coloring JavaScript...');
- init_pretty_print();
- window.prettyPrint();
- }, 400);
+ log('[ReadableJS]: Formatting JavaScript...');
+ code.textContent = make_js_readable((s2b(storage['detect_packers']) ? unpacker_filter(code.textContent) : code.textContent),
+ {
+ indent_size: parseInt(storage['indent_size'],10),
+ indent_char: storage['indent_char'],
+ preserve_newlines: s2b(storage['preserve_newlines']),
+ braces_on_own_line: s2b(storage['braces_on_own_line']),
+ keep_array_indentation: s2b(storage['keep_array_indentation']),
+ space_after_anon_function: true
+ }
+ );
+ }, s2b(storage['autoparse_js']) ? 0 : 300);
+
+ if (s2b(storage['enable_coloring'])) {
+ setTimeout(function () {
+ log('[ReadableJS]: Coloring JavaScript...');
+ init_pretty_print();
+ window.prettyPrint();
+ }, s2b(storage['autoparse_js']) ? 100 : 400);
+ }
}
- }, false);
function hideNotification() {
notification.className = 'hidden';
View
6 index.html
@@ -1,11 +1,10 @@
-<!doctype html>
+<!DOCTYPE html>
<html>
<head>
<title>Readable JavaScript</title>
<script type="text/javascript">
window.addEventListener('load', function () {
- function s2b(s) { return s === 'true' ? true : false; }
- if (!s2b(widget.preferences['enable_button'])) return;
+if (typeof widget === 'undefined' || typeof widget.preferences === 'undefined' || (widget.preferences['enable_button'] === 'true')) {
var theButton;
var toolbarUIItemProperties = {
title: 'Readable JavaScript',
@@ -18,6 +17,7 @@
}
theButton = opera.contexts.toolbar.createItem(toolbarUIItemProperties);
opera.contexts.toolbar.addItem(theButton);
+}
}, false);
</script>
</head>
View
67 options.html
@@ -1,67 +1,86 @@
-<!doctype html>
+<!DOCTYPE html>
<html>
<head>
<meta charset='utf_8'>
<link rel='stylesheet' href='css/options.css'>
+<script type='text/javascript' src='includes/common.js'></script>
<title id='widget_title'>Opera Extensions | Readable JavaScript</title>
</head>
<body>
<header>
<img src='icons/icon.png'>
-<h1 id='widget_name'>Readable JavaScript v1.0</h1>
+<h1 id='widget_name'>Readable JavaScript v1.1</h1>
</header>
<section>
-<h3>Preferences</h3>
+<h3 id='label_preferences'>Preferences</h3>
<fieldset>
<input type='checkbox' id='enable_button'/>
-<label for='enable_button'>Toolbar button (restart needed)</label>
+<label for='enable_button' id='enable_button_label'>Toolbar button (browser restart needed)</label>
+<br/>
+<input type='checkbox' id='autoparse_js'/>
+<label for='autoparse_js' id='autoparse_js_label'>Disable confirmation popup for files (auto-parse)</label>
<br/><br/>
-<label for='indent_size'>Indentation:</label>
-<select id='indent_size'>
-<option value='1'>with a tab character</option>
-<option value='2'>with 2 spaces</option>
-<option value='3'>with 3 spaces</option>
-<option value='4'>with 4 spaces</option>
-<option value='8'>with 8 spaces</option>
-</select>
+<fieldset id='indent_size'><legend id='indent_size_label'>Indentation:</legend>
+<input type='radio' value='1' name='indent_size' id='indent_size_tab'>
+<label for='indent_size_tab' id='indent_size_tab_label'>tab character</label><br />
+<input type='radio' value='2' name='indent_size' id='indent_size_two'>
+<label for='indent_size_two' id='indent_size_two_label'>2 spaces</label><br />
+<input type='radio' value='3' name='indent_size' id='indent_size_three'>
+<label for='indent_size_three' id='indent_size_three_label'>3 spaces</label><br />
+<input type='radio' value='4' name='indent_size' id='indent_size_four'>
+<label for='indent_size_four' id='indent_size_four_label'>4 spaces</label><br />
+<input type='radio' value='8' name='indent_size' id='indent_size_eight'>
+<label for='indent_size_eight' id='indent_size_eight_label'>8 spaces</label><br />
+</fieldset>
<br/>
<input type='checkbox' id='braces_on_own_line'/>
-<label for='braces_on_own_line'>Braces on own line</label>
+<label for='braces_on_own_line' id='braces_on_own_line_label'>Braces on own line</label>
<br/>
<input type='checkbox' id='preserve_newlines'/>
-<label for='preserve_newlines'>Preserve empty lines</label>
+<label for='preserve_newlines' id='preserve_newlines_label'>Preserve empty lines</label>
<br/>
<input type='checkbox' id='detect_packers'/>
-<label for='detect_packers'> Detect packers</label>
+<label for='detect_packers' id='detect_packers_label'> Detect packers</label>
<br/>
<input type='checkbox' id='keep_array_indentation'/>
-<label for='keep_array_indentation'>Keep array indentation</label>
+<label for='keep_array_indentation_label' id='keep_array_indentation_label'>Keep array indentation</label>
<br/>
<input type='checkbox' id='enable_coloring'/>
-<label for='enable_coloring'>Syntax highlighting (very slow)</label>
+<label for='enable_coloring' id='enable_coloring_label'>Syntax highlighting (very slow)</label>
<br/>
<input type='checkbox' id='debug_output'/>
-<label for='debug_output'><b>Debug</b> output</label>
+<label for='debug_output' id='debug_output_label'>Debug output</label>
</fieldset>
<br /><p></p>
</section>
<footer>
-<p>Powered by the Opera Browser</p>
+<p id='footer_text'>Powered by the Opera Browser</p>
</footer>
<script>
+document.getElementsByTagName('html')[0].setAttribute('lang', window.navigator.language.slice(0,2));
addEventListener('DOMContentLoaded', function() {
-var storage = widget.preferences;
-function s2b(s){return s === 'true' ? true : false; }
+var storage;
+if (typeof widget === 'undefined' || typeof widget.preferences === 'undefined' ) {window.alert("Opera "+(window.navigator.userAgent.match(/(Version\/)(\d+\.\d+)/))[2]+" doesn't support widget.preferences.\nThis extension will be always using predefined options.");
+storage = {'autoparse_js': 'false','enable_button': 'true','indent_size': '4','preserve_newlines':'true','keep_array_indentation':'true','detect_packers':'true','braces_on_own_line':'false','indent_char':' ','debug_output':'false','enable_coloring':'false'}
+} else { storage = widget.preferences; }
+
+function setRadioValue(radioNodeList, value) {
+ if (!radioNodeList || typeof value !== 'number') return;
+ for (var i = radioNodeList.length - 1; i > -1; i--) {
+ if (radioNodeList[i].value == value) return radioNodeList[i].checked = true;
+ }
+}
function setOptions() {
+setRadioValue(document.querySelectorAll('input[name="indent_size"]'), parseInt(storage['indent_size'],10));
+document.querySelector('#autoparse_js').checked = s2b(storage['autoparse_js']);
document.querySelector('#enable_button').checked = s2b(storage['enable_button']);
-document.querySelector('#indent_size').value = Number(storage['indent_size'])
document.querySelector('#preserve_newlines').checked = s2b(storage['preserve_newlines']);
document.querySelector('#keep_array_indentation').checked = s2b(storage['keep_array_indentation']);
document.querySelector('#braces_on_own_line').checked = s2b(storage['braces_on_own_line']);
@@ -72,6 +91,7 @@ <h1 id='widget_name'>Readable JavaScript v1.0</h1>
function saveOptions() {
var options = getOptions();
+ storage['autoparse_js'] = options.autoparse_js;
storage['enable_button'] = options.enable_button;
storage['indent_size'] = options.indent_size;
storage['preserve_newlines'] = options.preserve_newlines;
@@ -86,8 +106,9 @@ <h1 id='widget_name'>Readable JavaScript v1.0</h1>
function getOptions() {
return {
+ autoparse_js: document.querySelector('#autoparse_js').checked,
enable_button: document.querySelector('#enable_button').checked,
- indent_size: document.querySelector('#indent_size').value,
+ indent_size: document.querySelector('input[name="indent_size"]:checked').value,
preserve_newlines: document.querySelector('#preserve_newlines').checked,
keep_array_indentation: document.querySelector('#keep_array_indentation').checked,
detect_packers: document.querySelector('#detect_packers').checked,
View
118 popup.html
@@ -1,121 +1,45 @@
-<!doctype html>
+<!DOCTYPE html>
<html>
<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Readable JavaScript</title>
-<style type="text/css">
-* {
-margin: 0 0 0 0;
-padding: 0 0 0 0;
-}
-body {
-font-size:14px;
-font-family: "arial", "helvetica", sans-serif;
-overflow:hidden;
-padding-right:4px;
-padding-top:4px;
-}
-fieldset{
-border: none;
-}
-textarea {
-font-family: "consolas", "Terminus", "lucida console", "courier new", "courier", monospace;
-font-size: 12px;
-}
-button {
-background:#eee;
-padding:3px 5px;
-border-bottom-color:#999;
-border-bottom-style:solid;
-border-bottom-width:1px;
-border-left-color:#ccc;
-border-left-style:solid;
-border-left-width:1px;
-border-right-color:#999;
-border-right-style:solid;
-border-right-width:1px;
-border-top-color:#ccc;
-border-top-style:solid;
-border-top-width:1px;
-cursor:pointer;
-margin-top:2px;
-width:100%
-}
-</style>
-<script type="text/javascript" src="includes/readable_js.js"></script>
-<script type="text/javascript" src="includes/unpacker_bookmarklet.js"></script>
-<script type="text/javascript" src="includes/unpacker_javascriptobfuscator.js"></script>
-<script type="text/javascript" src="includes/unpacker_p_a_c_k_e_r.js"></script>
-<script type="text/javascript">
-var storage = widget.preferences;
-
-function s2b(s) { return s === 'true' ? true : false; }
-function log(){ if (s2b(storage['debug_output'])) opera.postError(Array.prototype.slice.call(arguments))}
-
-function trim_comments(str)
-{
- var lines = str.split('\n'), tmp = '';
- for (var i = 0; i < lines.length; i++) tmp += lines[i].replace(/([^\x2f]*)\x2f\x2f.*$/, '$1');
- lines = tmp.split('*/');
- tmp = '';
- for (var i = 0; i < lines.length; i++) tmp += lines[i].replace(/(.*)\x2f\x2a(.*)$/g, '$1 ');
- tmp = tmp.replace(/^\s+/g, '');
- return tmp;
-}
-
-function unpacker_filter(source)
-{
- var stripped_source = trim_comments(source);
- var unpacked = '';
-
- if (!s2b(storage['detect_packers'])) return source;
-
- if (P_A_C_K_E_R.detect(stripped_source)) {
- unpacked = P_A_C_K_E_R.unpack(stripped_source);
- if (unpacked !== stripped_source) {
- return unpacker_filter(unpacked);
- }
- }
+<link rel='stylesheet' href='css/popup.css'>
+<script type='text/javascript' src='includes/readable_js.js'></script>
+<script type='text/javascript' src='includes/unpacker_bookmarklet.js'></script>
+<script type='text/javascript' src='includes/unpacker_javascriptobfuscator.js'></script>
+<script type='text/javascript' src='includes/unpacker_p_a_c_k_e_r.js'></script>
+<script type='text/javascript' src='includes/common.js'></script>
+<script type='text/javascript'>
+document.getElementsByTagName('html')[0].setAttribute('lang', window.navigator.language.slice(0,2));
- if (EscapedBookmarklet.detect(source)) {
- unpacked = EscapedBookmarklet.unpack(source);
- if (unpacked !== stripped_source) {
- return unpacker_filter(unpacked);
- }
- }
-
- if (JavascriptObfuscator.detect(stripped_source)) {
- unpacked = JavascriptObfuscator.unpack(stripped_source);
- if (unpacked !== stripped_source) {
- return unpacker_filter(unpacked);
- }
- }
- return source;
-}
+var storage;
+if (typeof widget === 'undefined' || typeof widget.preferences === 'undefined') {
+ storage = {'autoparse_js': 'false','enable_button': 'true','indent_size': '4','preserve_newlines':'true','keep_array_indentation':'true','detect_packers':'true','braces_on_own_line':'false','indent_char':' ','debug_output':'false','enable_coloring':'false'}
+} else { storage = widget.preferences; }
function make_readable() {
- if (document.getElementById('inputjs').value === '') return;
+ var sourcecode = document.getElementById('inputjs').value;
+ if (sourcecode === '') return;
document.getElementById('makereadable').disabled = true;
- var newjs = make_js_readable(unpacker_filter(document.getElementById('inputjs').value), {
- indent_size: Number(storage['indent_size'], 10),
+ var newjs = make_js_readable((s2b(storage['detect_packers']) ? unpacker_filter(sourcecode) : sourcecode),{
+ indent_size: parseInt(storage['indent_size'], 10),
indent_char: storage['indent_char'],
preserve_newlines: s2b(storage['preserve_newlines']),
braces_on_own_line: s2b(storage['braces_on_own_line']),
keep_array_indentation: s2b(storage['keep_array_indentation']),
space_after_anon_function: true
});
-
+
document.getElementById('inputjs').value = newjs;
setTimeout(function(){document.getElementById('makereadable').disabled = false;},100);
}
</script>
</head>
-<body onload="javascript:document.getElementById('inputjs').focus();">
+<body onload="document.getElementById('inputjs').focus()">
<form action="?" method="post">
<fieldset class="inputjsbox">
- <label for="inputjs">JavaScript: </label><br><textarea id="inputjs" type="text" name="inputjs" cols="82" rows="25" required placeholder="/*JavaScript code*/ var test=1; function test(){var a = test; return;}"></textarea>
- <button onclick="make_readable()" id="makereadable">Make Readable</button>
+ <label id="labeljs" for="inputjs">JavaScript: </label><br><textarea id="inputjs" type="text" name="inputjs" cols="82" rows="25" required placeholder="/*JavaScript code*/ var test=1; function test(){var a = test; return;}"></textarea>
+ <button onclick="make_readable()" id="makereadable">Make readable</button>
</fieldset>
</form>
</body>

0 comments on commit 20af6e3

Please sign in to comment.