├── README.md
├── css
├── bootstrap.min.css
├── common.css
├── flat-ui.css
├── flat-ui.css.map
└── flat-ui.min.css
├── fonts
├── glyphicons
│ ├── flat-ui-icons-regular.eot
│ ├── flat-ui-icons-regular.svg
│ ├── flat-ui-icons-regular.ttf
│ ├── flat-ui-icons-regular.woff
│ └── selection.json
└── lato
│ ├── lato-black.eot
│ ├── lato-black.svg
│ ├── lato-black.ttf
│ ├── lato-black.woff
│ ├── lato-bold.eot
│ ├── lato-bold.svg
│ ├── lato-bold.ttf
│ ├── lato-bold.woff
│ ├── lato-bolditalic.eot
│ ├── lato-bolditalic.svg
│ ├── lato-bolditalic.ttf
│ ├── lato-bolditalic.woff
│ ├── lato-italic.eot
│ ├── lato-italic.svg
│ ├── lato-italic.ttf
│ ├── lato-italic.woff
│ ├── lato-light.eot
│ ├── lato-light.svg
│ ├── lato-light.ttf
│ ├── lato-light.woff
│ ├── lato-regular.eot
│ ├── lato-regular.svg
│ ├── lato-regular.ttf
│ └── lato-regular.woff
├── img
├── favicon.ico
├── icons
│ ├── png
│ │ ├── Book.png
│ │ ├── Calendar.png
│ │ ├── Chat.png
│ │ ├── Clipboard.png
│ │ ├── Compas.png
│ │ ├── Gift-Box.png
│ │ ├── Infinity-Loop.png
│ │ ├── Mail.png
│ │ ├── Map.png
│ │ ├── Pensils.png
│ │ ├── Pocket.png
│ │ ├── Retina-Ready.png
│ │ ├── Toilet-Paper.png
│ │ └── Watches.png
│ └── svg
│ │ ├── book.svg
│ │ ├── calendar.svg
│ │ ├── chat.svg
│ │ ├── clipboard.svg
│ │ ├── clocks.svg
│ │ ├── compas.svg
│ │ ├── gift-box.svg
│ │ ├── loop.svg
│ │ ├── mail.svg
│ │ ├── map.svg
│ │ ├── paper-bag.svg
│ │ ├── pencils.svg
│ │ ├── retina.svg
│ │ ├── ribbon.svg
│ │ └── toilet-paper.svg
├── login
│ ├── icon.png
│ ├── imac-2x.png
│ └── imac.png
├── logo
│ ├── icon128.png
│ ├── icon16.png
│ └── icon48.png
└── tile
│ ├── ribbon-2x.png
│ └── ribbon.png
├── js
├── background.js
├── common.js
├── cssbeautify.js
├── flat-ui.js
├── flat-ui.min.js
├── html5shiv.js
├── jquery.endecode.js
├── jquery.min.js
├── jquery.min.map
├── jquery.qrcode.js
├── jsbeautify.js
├── popup.js
└── respond.min.js
├── manifest.json
└── popup.html
/README.md:
--------------------------------------------------------------------------------
1 | #Tiny tools
2 | Tiny tools is a simple tool Chrome extension, which contains a lot of useful tools, such as QR code generator, QR code decoder, translation, timestamp conversion, source format, JSON format, image Base64, character encode, etc.
3 |
4 | #Tiny tools
5 | Tiny tools(迷你工具)是一个Chrome的扩展,其中包含了很多有用的工具,如QR码生成器,QR码解码、翻译,时间戳转换,源格式,JSON格式,图像base64字符编码等等。
6 |
7 | ##特色功能
8 | 1. 优先从剪贴板读取内容(支持文字和图片),其次再读取浏览器当前页面的URL
9 | 2. 支持直接解码QR和生成图片Base64
10 | 3. 支持识别Unix时间戳并生成相应的日期时间
11 | 4. 支持CSS、Javascript、HTML、XML、SQL、JSON代码格式化
12 | 5. 支持Urlencode、Urldecode、Uniencode、Unidecode
13 |
14 | ##插件下载
15 | [CRX文件下载](https://github.com/karsonzhang/tinytools/releases)
16 |
17 | ##运行截图
18 | 
19 | 
20 | 
21 | 
22 |
--------------------------------------------------------------------------------
/css/common.css:
--------------------------------------------------------------------------------
1 | @media (max-width: 600px) {
2 | body {min-width:600px;}
3 | }
4 |
5 | #header {border-bottom:1px solid #f7f7f7;margin-bottom:10px;}
6 | .select,.select2-drop,.multiselect {min-width: 50px;}
7 | #sandbox {position:absolute;left:-9999px;top:-9999px;width:0;height:0;}
8 | .btn-alimama{margin-bottom:10px;}
--------------------------------------------------------------------------------
/fonts/glyphicons/flat-ui-icons-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/fonts/glyphicons/flat-ui-icons-regular.eot
--------------------------------------------------------------------------------
/fonts/glyphicons/flat-ui-icons-regular.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/fonts/glyphicons/flat-ui-icons-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/fonts/glyphicons/flat-ui-icons-regular.ttf
--------------------------------------------------------------------------------
/fonts/glyphicons/flat-ui-icons-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/fonts/glyphicons/flat-ui-icons-regular.woff
--------------------------------------------------------------------------------
/fonts/lato/lato-black.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/fonts/lato/lato-black.eot
--------------------------------------------------------------------------------
/fonts/lato/lato-black.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/fonts/lato/lato-black.ttf
--------------------------------------------------------------------------------
/fonts/lato/lato-black.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/fonts/lato/lato-black.woff
--------------------------------------------------------------------------------
/fonts/lato/lato-bold.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/fonts/lato/lato-bold.eot
--------------------------------------------------------------------------------
/fonts/lato/lato-bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/fonts/lato/lato-bold.ttf
--------------------------------------------------------------------------------
/fonts/lato/lato-bold.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/fonts/lato/lato-bold.woff
--------------------------------------------------------------------------------
/fonts/lato/lato-bolditalic.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/fonts/lato/lato-bolditalic.eot
--------------------------------------------------------------------------------
/fonts/lato/lato-bolditalic.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/fonts/lato/lato-bolditalic.ttf
--------------------------------------------------------------------------------
/fonts/lato/lato-bolditalic.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/fonts/lato/lato-bolditalic.woff
--------------------------------------------------------------------------------
/fonts/lato/lato-italic.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/fonts/lato/lato-italic.eot
--------------------------------------------------------------------------------
/fonts/lato/lato-italic.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/fonts/lato/lato-italic.ttf
--------------------------------------------------------------------------------
/fonts/lato/lato-italic.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/fonts/lato/lato-italic.woff
--------------------------------------------------------------------------------
/fonts/lato/lato-light.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/fonts/lato/lato-light.eot
--------------------------------------------------------------------------------
/fonts/lato/lato-light.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/fonts/lato/lato-light.ttf
--------------------------------------------------------------------------------
/fonts/lato/lato-light.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/fonts/lato/lato-light.woff
--------------------------------------------------------------------------------
/fonts/lato/lato-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/fonts/lato/lato-regular.eot
--------------------------------------------------------------------------------
/fonts/lato/lato-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/fonts/lato/lato-regular.ttf
--------------------------------------------------------------------------------
/fonts/lato/lato-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/fonts/lato/lato-regular.woff
--------------------------------------------------------------------------------
/img/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/img/favicon.ico
--------------------------------------------------------------------------------
/img/icons/png/Book.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/img/icons/png/Book.png
--------------------------------------------------------------------------------
/img/icons/png/Calendar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/img/icons/png/Calendar.png
--------------------------------------------------------------------------------
/img/icons/png/Chat.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/img/icons/png/Chat.png
--------------------------------------------------------------------------------
/img/icons/png/Clipboard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/img/icons/png/Clipboard.png
--------------------------------------------------------------------------------
/img/icons/png/Compas.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/img/icons/png/Compas.png
--------------------------------------------------------------------------------
/img/icons/png/Gift-Box.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/img/icons/png/Gift-Box.png
--------------------------------------------------------------------------------
/img/icons/png/Infinity-Loop.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/img/icons/png/Infinity-Loop.png
--------------------------------------------------------------------------------
/img/icons/png/Mail.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/img/icons/png/Mail.png
--------------------------------------------------------------------------------
/img/icons/png/Map.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/img/icons/png/Map.png
--------------------------------------------------------------------------------
/img/icons/png/Pensils.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/img/icons/png/Pensils.png
--------------------------------------------------------------------------------
/img/icons/png/Pocket.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/img/icons/png/Pocket.png
--------------------------------------------------------------------------------
/img/icons/png/Retina-Ready.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/img/icons/png/Retina-Ready.png
--------------------------------------------------------------------------------
/img/icons/png/Toilet-Paper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/img/icons/png/Toilet-Paper.png
--------------------------------------------------------------------------------
/img/icons/png/Watches.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/img/icons/png/Watches.png
--------------------------------------------------------------------------------
/img/icons/svg/book.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/img/icons/svg/calendar.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/img/icons/svg/chat.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/img/icons/svg/clipboard.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/img/icons/svg/clocks.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/img/icons/svg/compas.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/img/icons/svg/gift-box.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/img/icons/svg/loop.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/img/icons/svg/mail.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/img/icons/svg/map.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/img/icons/svg/paper-bag.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/img/icons/svg/pencils.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/img/icons/svg/retina.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/img/icons/svg/ribbon.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
40 |
--------------------------------------------------------------------------------
/img/icons/svg/toilet-paper.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/img/login/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/img/login/icon.png
--------------------------------------------------------------------------------
/img/login/imac-2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/img/login/imac-2x.png
--------------------------------------------------------------------------------
/img/login/imac.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/img/login/imac.png
--------------------------------------------------------------------------------
/img/logo/icon128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/img/logo/icon128.png
--------------------------------------------------------------------------------
/img/logo/icon16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/img/logo/icon16.png
--------------------------------------------------------------------------------
/img/logo/icon48.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/img/logo/icon48.png
--------------------------------------------------------------------------------
/img/tile/ribbon-2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/img/tile/ribbon-2x.png
--------------------------------------------------------------------------------
/img/tile/ribbon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karsonzhang/tinytools/582081493d684bace4ede089104b1ab6ecebb7bd/img/tile/ribbon.png
--------------------------------------------------------------------------------
/js/background.js:
--------------------------------------------------------------------------------
1 | var onClickHandler = function (info, tab) {
2 | var data = "";
3 | if (info.menuItemId == "tinytools-page") {
4 | data = info.pageUrl;
5 | } else if (info.menuItemId == "tinytools-selection") {
6 | data = info.selectionText;
7 | } else if (info.menuItemId == "tinytools-link") {
8 | data = info.linkUrl;
9 | }
10 | data = data.replace(/"/g, '\\"');
11 | chrome.tabs.executeScript(tab.id, {"code": "typeof buildqrcode"}, function (context) {
12 | if (context && context[0] == "undefined") {
13 | chrome.tabs.executeScript(tab.id, {"file": "js/jquery.min.js"}, function () {
14 | chrome.tabs.executeScript(tab.id, {"file": "js/jquery.qrcode.js"}, function () {
15 | chrome.tabs.executeScript(tab.id, {"file": "js/common.js"}, function () {
16 | chrome.tabs.executeScript(tab.id, {"code": "buildqrcode(\"" + data + "\");"});
17 | });
18 | });
19 | });
20 | } else {
21 | chrome.tabs.executeScript(tab.id, {"code": "buildqrcode(\"" + data + "\");"});
22 | }
23 | });
24 | };
25 |
26 | var onInstallHandler = function () {
27 | var contexts = ["page", "selection", "link"];
28 | var texts = ["当前页面", "所选文本", "所选链接"];
29 | for (var i = 0; i < contexts.length; i++) {
30 | var title = "为" + texts[i] + "生成二维码";
31 | var context = contexts[i];
32 | chrome.contextMenus.create({"title": title, "contexts": [context], "id": "tinytools-" + context});
33 | }
34 | };
35 |
36 | var onBeforeRequestHandler = function (details) {
37 | var url = details.url;
38 | var domain = url.match(/^(http|https)\:\/\/([a-zA-Z0-9\.\-])+/g);
39 | var judge = false;
40 | var replaceobj = {
41 | 'fonts.googleapis.com': 'fonts.lug.ustc.edu.cn',
42 | 'ajax.googleapis.com': 'ajax.lug.ustc.edu.cn',
43 | 'themes.googleusercontent.com': 'google-themes.lug.ustc.edu.cn',
44 | 'fonts.gstatic.com': 'fonts-gstatic.lug.ustc.edu.cn',
45 | 'www.gravatar.com': 'gravatar.lug.ustc.edu.cn'
46 | };
47 | var search = "";
48 | for (var key in replaceobj) {
49 | if (replaceobj.hasOwnProperty(key)) {
50 | judge = domain && domain[0].indexOf(key) > -1;
51 | if (judge) {
52 | search = key;
53 | break;
54 | }
55 | }
56 | }
57 |
58 | if (judge) {
59 | url = url.replace(search, replaceobj[search]);
60 | return {redirectUrl: url};
61 | }
62 | };
63 |
64 | //添加右键菜单事件
65 | chrome.contextMenus.onClicked.addListener(onClickHandler);
66 | //添加事件
67 | chrome.runtime.onInstalled.addListener(onInstallHandler);
68 | //替换GoogleAPI https://servers.blog.ustc.edu.cn/2015/09/google-revproxy-add-cache/
69 | chrome.webRequest.onBeforeRequest.addListener(onBeforeRequestHandler, {urls: [""]}, ["blocking"]);
--------------------------------------------------------------------------------
/js/common.js:
--------------------------------------------------------------------------------
1 |
2 | var st;
3 | var url;
4 | var clipboard = {type: "", content: "", url: ""};
5 |
6 | var utf8text = function (text) {
7 | text = String(text).replace(
8 | /[\u0080-\u07ff]/g,
9 | function (c) {
10 | var cc = c.charCodeAt(0);
11 | return String.fromCharCode(0xc0 | cc >> 6, 0x80 | cc & 0x3f);
12 | }
13 | ).replace(
14 | /[\u0800-\uffff]/g,
15 | function (c) {
16 | var cc = c.charCodeAt(0);
17 | return String.fromCharCode(0xe0 | cc >> 12, 0x80 | cc >> 6 & 0x3f, 0x80 | cc & 0x3f);
18 | }
19 | );
20 | return text;
21 | };
22 |
23 | var buildqrcode = function (qrtext) {
24 | var size = 400;
25 | var div = $("");
26 | var qrdiv = $("");
27 | div.click(function () {
28 | div.remove();
29 | qrdiv.remove();
30 | $(document).unbind("keyup");
31 | });
32 | $(document).bind("keyup", function (e) {
33 | e = e || window.event;
34 | var k = e.keyCode;
35 | if (k == 32 || k == 27) {
36 | div.click();
37 | }
38 | });
39 | $("body").append(div);
40 | $("body").append(qrdiv);
41 | div.css({
42 | 'position': 'fixed',
43 | 'top': 0,
44 | 'left': 0,
45 | 'width': '100%',
46 | 'height': '100%',
47 | 'z-index': '9999'});
48 | $(div).css('background-color', 'rgba(0,0,0,.85)');
49 | $(qrdiv).css({
50 | top: div.height() / 2 - size / 2,
51 | left: div.width() / 2 - size / 2,
52 | width: size + 'px',
53 | height: size + 'px',
54 | position: 'fixed',
55 | background: 'white',
56 | 'z-index': '10000'
57 | });
58 | $(qrdiv).qrcode({
59 | "render": "image",
60 | "size": size,
61 | "color": "#3a3",
62 | "text": utf8text(qrtext)
63 | });
64 | };
65 |
66 | var copy = function (str) {
67 | var sandbox = $('#sandbox').val(str).select();
68 | document.execCommand('copy');
69 | clipboard.type = "text";
70 | clipboard.content = sandbox;
71 | clipboard.url = "";
72 | sandbox.val('');
73 | };
74 |
75 | var paste = function () {
76 | var result = '',
77 | sandbox = $('#sandbox').val('').select();
78 | if (document.execCommand('paste')) {
79 | result = sandbox.val();
80 | }
81 | sandbox.val('');
82 | return result;
83 | };
--------------------------------------------------------------------------------
/js/cssbeautify.js:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2011 Sencha Inc.
3 |
4 | Author: Ariya Hidayat.
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | */
24 |
25 | /*jslint continue: true, indent: 4 */
26 |
27 | function cssbeautify(style, opt) {
28 | 'use strict';
29 |
30 | var options, index = 0, length = style.length, blocks, formatted = '',
31 | ch, ch2, str, state, State, depth, quote, comment,
32 | openbracesuffix = true,
33 | trimRight;
34 |
35 | options = arguments.length > 1 ? opt : {};
36 | if (typeof options.indent === 'undefined') {
37 | options.indent = ' ';
38 | }
39 | if (typeof options.openbrace === 'string') {
40 | openbracesuffix = (options.openbrace === 'end-of-line');
41 | }
42 |
43 | function isWhitespace(c) {
44 | return (c === ' ') || (c === '\n') || (c === '\t') || (c === '\r') || (c === '\f');
45 | }
46 |
47 | function isQuote(c) {
48 | return (c === '\'') || (c === '"');
49 | }
50 |
51 | // FIXME: handle Unicode characters
52 | function isName(c) {
53 | return (ch >= 'a' && ch <= 'z') ||
54 | (ch >= 'A' && ch <= 'Z') ||
55 | (ch >= '0' && ch <= '9') ||
56 | '-_*.:#'.indexOf(c) >= 0;
57 | }
58 |
59 | function appendIndent() {
60 | var i;
61 | for (i = depth; i > 0; i -= 1) {
62 | formatted += options.indent;
63 | }
64 | }
65 |
66 | function openBlock() {
67 | formatted = trimRight(formatted);
68 | if (openbracesuffix) {
69 | formatted += ' {';
70 | } else {
71 | formatted += '\n';
72 | appendIndent();
73 | formatted += '{';
74 | }
75 | if (ch2 !== '\n') {
76 | formatted += '\n';
77 | }
78 | depth += 1;
79 | }
80 |
81 | function closeBlock() {
82 | depth -= 1;
83 | formatted = trimRight(formatted);
84 | formatted += '\n';
85 | appendIndent();
86 | formatted += '}';
87 | blocks.push(formatted);
88 | formatted = '';
89 | }
90 |
91 | if (String.prototype.trimRight) {
92 | trimRight = function (s) {
93 | return s.trimRight();
94 | };
95 | } else {
96 | // old Internet Explorer
97 | trimRight = function (s) {
98 | return s.replace(/\s+$/, '');
99 | };
100 | }
101 |
102 | State = {
103 | Start: 0,
104 | AtRule: 1,
105 | Block: 2,
106 | Selector: 3,
107 | Ruleset: 4,
108 | Property: 5,
109 | Separator: 6,
110 | Expression: 7
111 | };
112 |
113 | depth = 0;
114 | state = State.Start;
115 | comment = false;
116 | blocks = [];
117 |
118 | // We want to deal with LF (\n) only
119 | style = style.replace(/\r\n/g, '\n');
120 |
121 | while (index < length) {
122 | ch = style.charAt(index);
123 | ch2 = style.charAt(index + 1);
124 | index += 1;
125 |
126 | // Inside a string literal?
127 | if (isQuote(quote)) {
128 | formatted += ch;
129 | if (ch === quote) {
130 | quote = null;
131 | }
132 | if (ch === '\\' && ch2 === quote) {
133 | // Don't treat escaped character as the closing quote
134 | formatted += ch2;
135 | index += 1;
136 | }
137 | continue;
138 | }
139 |
140 | // Starting a string literal?
141 | if (isQuote(ch)) {
142 | formatted += ch;
143 | quote = ch;
144 | continue;
145 | }
146 |
147 | // Comment
148 | if (comment) {
149 | formatted += ch;
150 | if (ch === '*' && ch2 === '/') {
151 | comment = false;
152 | formatted += ch2;
153 | index += 1;
154 | }
155 | continue;
156 | } else {
157 | if (ch === '/' && ch2 === '*') {
158 | comment = true;
159 | formatted += ch;
160 | formatted += ch2;
161 | index += 1;
162 | continue;
163 | }
164 | }
165 |
166 | if (state === State.Start) {
167 |
168 | if (blocks.length === 0) {
169 | if (isWhitespace(ch) && formatted.length === 0) {
170 | continue;
171 | }
172 | }
173 |
174 | // Copy white spaces and control characters
175 | if (ch <= ' ' || ch.charCodeAt(0) >= 128) {
176 | state = State.Start;
177 | formatted += ch;
178 | continue;
179 | }
180 |
181 | // Selector or at-rule
182 | if (isName(ch) || (ch === '@')) {
183 |
184 | // Clear trailing whitespaces and linefeeds.
185 | str = trimRight(formatted);
186 |
187 | if (str.length === 0) {
188 | // If we have empty string after removing all the trailing
189 | // spaces, that means we are right after a block.
190 | // Ensure a blank line as the separator.
191 | if (blocks.length > 0) {
192 | formatted = '\n\n';
193 | }
194 | } else {
195 | // After finishing a ruleset or directive statement,
196 | // there should be one blank line.
197 | if (str.charAt(str.length - 1) === '}' ||
198 | str.charAt(str.length - 1) === ';') {
199 |
200 | formatted = str + '\n\n';
201 | } else {
202 | // After block comment, keep all the linefeeds but
203 | // start from the first column (remove whitespaces prefix).
204 | while (true) {
205 | ch2 = formatted.charAt(formatted.length - 1);
206 | if (ch2 !== ' ' && ch2.charCodeAt(0) !== 9) {
207 | break;
208 | }
209 | formatted = formatted.substr(0, formatted.length - 1);
210 | }
211 | }
212 | }
213 | formatted += ch;
214 | state = (ch === '@') ? State.AtRule : State.Selector;
215 | continue;
216 | }
217 | }
218 |
219 | if (state === State.AtRule) {
220 |
221 | // ';' terminates a statement.
222 | if (ch === ';') {
223 | formatted += ch;
224 | state = State.Start;
225 | continue;
226 | }
227 |
228 | // '{' starts a block
229 | if (ch === '{') {
230 | openBlock();
231 | state = State.Block;
232 | continue;
233 | }
234 |
235 | formatted += ch;
236 | continue;
237 | }
238 |
239 | if (state === State.Block) {
240 |
241 | // Selector
242 | if (isName(ch)) {
243 |
244 | // Clear trailing whitespaces and linefeeds.
245 | str = trimRight(formatted);
246 |
247 | if (str.length === 0) {
248 | // If we have empty string after removing all the trailing
249 | // spaces, that means we are right after a block.
250 | // Ensure a blank line as the separator.
251 | if (blocks.length > 0) {
252 | formatted = '\n\n';
253 | }
254 | } else {
255 | // Insert blank line if necessary.
256 | if (str.charAt(str.length - 1) === '}') {
257 | formatted = str + '\n\n';
258 | } else {
259 | // After block comment, keep all the linefeeds but
260 | // start from the first column (remove whitespaces prefix).
261 | while (true) {
262 | ch2 = formatted.charAt(formatted.length - 1);
263 | if (ch2 !== ' ' && ch2.charCodeAt(0) !== 9) {
264 | break;
265 | }
266 | formatted = formatted.substr(0, formatted.length - 1);
267 | }
268 | }
269 | }
270 |
271 | appendIndent();
272 | formatted += ch;
273 | state = State.Selector;
274 | continue;
275 | }
276 |
277 | // '}' resets the state.
278 | if (ch === '}') {
279 | closeBlock();
280 | state = State.Start;
281 | continue;
282 | }
283 |
284 | formatted += ch;
285 | continue;
286 | }
287 |
288 | if (state === State.Selector) {
289 |
290 | // '{' starts the ruleset.
291 | if (ch === '{') {
292 | openBlock();
293 | state = State.Ruleset;
294 | continue;
295 | }
296 |
297 | // '}' resets the state.
298 | if (ch === '}') {
299 | closeBlock();
300 | state = State.Start;
301 | continue;
302 | }
303 |
304 | formatted += ch;
305 | continue;
306 | }
307 |
308 | if (state === State.Ruleset) {
309 |
310 | // '}' finishes the ruleset.
311 | if (ch === '}') {
312 | closeBlock();
313 | state = State.Start;
314 | if (depth > 0) {
315 | state = State.Block;
316 | }
317 | continue;
318 | }
319 |
320 | // Make sure there is no blank line or trailing spaces inbetween
321 | if (ch === '\n') {
322 | formatted = trimRight(formatted);
323 | formatted += '\n';
324 | continue;
325 | }
326 |
327 | // property name
328 | if (!isWhitespace(ch)) {
329 | formatted = trimRight(formatted);
330 | formatted += '\n';
331 | appendIndent();
332 | formatted += ch;
333 | state = State.Property;
334 | continue;
335 | }
336 | formatted += ch;
337 | continue;
338 | }
339 |
340 | if (state === State.Property) {
341 |
342 | // ':' concludes the property.
343 | if (ch === ':') {
344 | formatted = trimRight(formatted);
345 | formatted += ': ';
346 | state = State.Expression;
347 | if (isWhitespace(ch2)) {
348 | state = State.Separator;
349 | }
350 | continue;
351 | }
352 |
353 | // '}' finishes the ruleset.
354 | if (ch === '}') {
355 | closeBlock();
356 | state = State.Start;
357 | if (depth > 0) {
358 | state = State.Block;
359 | }
360 | continue;
361 | }
362 |
363 | formatted += ch;
364 | continue;
365 | }
366 |
367 | if (state === State.Separator) {
368 |
369 | // Non-whitespace starts the expression.
370 | if (!isWhitespace(ch)) {
371 | formatted += ch;
372 | state = State.Expression;
373 | continue;
374 | }
375 |
376 | // Anticipate string literal.
377 | if (isQuote(ch2)) {
378 | state = State.Expression;
379 | }
380 |
381 | continue;
382 | }
383 |
384 | if (state === State.Expression) {
385 |
386 | // '}' finishes the ruleset.
387 | if (ch === '}') {
388 | closeBlock();
389 | state = State.Start;
390 | if (depth > 0) {
391 | state = State.Block;
392 | }
393 | continue;
394 | }
395 |
396 | // ';' completes the declaration.
397 | if (ch === ';') {
398 | formatted = trimRight(formatted);
399 | formatted += ';\n';
400 | state = State.Ruleset;
401 | continue;
402 | }
403 |
404 | formatted += ch;
405 | continue;
406 | }
407 |
408 | // The default action is to copy the character (to prevent
409 | // infinite loop).
410 | formatted += ch;
411 | }
412 |
413 | formatted = blocks.join('') + formatted;
414 |
415 | return formatted;
416 | }
417 |
--------------------------------------------------------------------------------
/js/html5shiv.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @preserve HTML5 Shiv 3.7.2 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed
3 | */
4 | ;(function(window, document) {
5 | /*jshint evil:true */
6 | /** version */
7 | var version = '3.7.2';
8 |
9 | /** Preset options */
10 | var options = window.html5 || {};
11 |
12 | /** Used to skip problem elements */
13 | var reSkip = /^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i;
14 |
15 | /** Not all elements can be cloned in IE **/
16 | var saveClones = /^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i;
17 |
18 | /** Detect whether the browser supports default html5 styles */
19 | var supportsHtml5Styles;
20 |
21 | /** Name of the expando, to work with multiple documents or to re-shiv one document */
22 | var expando = '_html5shiv';
23 |
24 | /** The id for the the documents expando */
25 | var expanID = 0;
26 |
27 | /** Cached data for each document */
28 | var expandoData = {};
29 |
30 | /** Detect whether the browser supports unknown elements */
31 | var supportsUnknownElements;
32 |
33 | (function() {
34 | try {
35 | var a = document.createElement('a');
36 | a.innerHTML = '';
37 | //if the hidden property is implemented we can assume, that the browser supports basic HTML5 Styles
38 | supportsHtml5Styles = ('hidden' in a);
39 |
40 | supportsUnknownElements = a.childNodes.length == 1 || (function() {
41 | // assign a false positive if unable to shiv
42 | (document.createElement)('a');
43 | var frag = document.createDocumentFragment();
44 | return (
45 | typeof frag.cloneNode == 'undefined' ||
46 | typeof frag.createDocumentFragment == 'undefined' ||
47 | typeof frag.createElement == 'undefined'
48 | );
49 | }());
50 | } catch(e) {
51 | // assign a false positive if detection fails => unable to shiv
52 | supportsHtml5Styles = true;
53 | supportsUnknownElements = true;
54 | }
55 |
56 | }());
57 |
58 | /*--------------------------------------------------------------------------*/
59 |
60 | /**
61 | * Creates a style sheet with the given CSS text and adds it to the document.
62 | * @private
63 | * @param {Document} ownerDocument The document.
64 | * @param {String} cssText The CSS text.
65 | * @returns {StyleSheet} The style element.
66 | */
67 | function addStyleSheet(ownerDocument, cssText) {
68 | var p = ownerDocument.createElement('p'),
69 | parent = ownerDocument.getElementsByTagName('head')[0] || ownerDocument.documentElement;
70 |
71 | p.innerHTML = 'x';
72 | return parent.insertBefore(p.lastChild, parent.firstChild);
73 | }
74 |
75 | /**
76 | * Returns the value of `html5.elements` as an array.
77 | * @private
78 | * @returns {Array} An array of shived element node names.
79 | */
80 | function getElements() {
81 | var elements = html5.elements;
82 | return typeof elements == 'string' ? elements.split(' ') : elements;
83 | }
84 |
85 | /**
86 | * Extends the built-in list of html5 elements
87 | * @memberOf html5
88 | * @param {String|Array} newElements whitespace separated list or array of new element names to shiv
89 | * @param {Document} ownerDocument The context document.
90 | */
91 | function addElements(newElements, ownerDocument) {
92 | var elements = html5.elements;
93 | if(typeof elements != 'string'){
94 | elements = elements.join(' ');
95 | }
96 | if(typeof newElements != 'string'){
97 | newElements = newElements.join(' ');
98 | }
99 | html5.elements = elements +' '+ newElements;
100 | shivDocument(ownerDocument);
101 | }
102 |
103 | /**
104 | * Returns the data associated to the given document
105 | * @private
106 | * @param {Document} ownerDocument The document.
107 | * @returns {Object} An object of data.
108 | */
109 | function getExpandoData(ownerDocument) {
110 | var data = expandoData[ownerDocument[expando]];
111 | if (!data) {
112 | data = {};
113 | expanID++;
114 | ownerDocument[expando] = expanID;
115 | expandoData[expanID] = data;
116 | }
117 | return data;
118 | }
119 |
120 | /**
121 | * returns a shived element for the given nodeName and document
122 | * @memberOf html5
123 | * @param {String} nodeName name of the element
124 | * @param {Document} ownerDocument The context document.
125 | * @returns {Object} The shived element.
126 | */
127 | function createElement(nodeName, ownerDocument, data){
128 | if (!ownerDocument) {
129 | ownerDocument = document;
130 | }
131 | if(supportsUnknownElements){
132 | return ownerDocument.createElement(nodeName);
133 | }
134 | if (!data) {
135 | data = getExpandoData(ownerDocument);
136 | }
137 | var node;
138 |
139 | if (data.cache[nodeName]) {
140 | node = data.cache[nodeName].cloneNode();
141 | } else if (saveClones.test(nodeName)) {
142 | node = (data.cache[nodeName] = data.createElem(nodeName)).cloneNode();
143 | } else {
144 | node = data.createElem(nodeName);
145 | }
146 |
147 | // Avoid adding some elements to fragments in IE < 9 because
148 | // * Attributes like `name` or `type` cannot be set/changed once an element
149 | // is inserted into a document/fragment
150 | // * Link elements with `src` attributes that are inaccessible, as with
151 | // a 403 response, will cause the tab/window to crash
152 | // * Script elements appended to fragments will execute when their `src`
153 | // or `text` property is set
154 | return node.canHaveChildren && !reSkip.test(nodeName) && !node.tagUrn ? data.frag.appendChild(node) : node;
155 | }
156 |
157 | /**
158 | * returns a shived DocumentFragment for the given document
159 | * @memberOf html5
160 | * @param {Document} ownerDocument The context document.
161 | * @returns {Object} The shived DocumentFragment.
162 | */
163 | function createDocumentFragment(ownerDocument, data){
164 | if (!ownerDocument) {
165 | ownerDocument = document;
166 | }
167 | if(supportsUnknownElements){
168 | return ownerDocument.createDocumentFragment();
169 | }
170 | data = data || getExpandoData(ownerDocument);
171 | var clone = data.frag.cloneNode(),
172 | i = 0,
173 | elems = getElements(),
174 | l = elems.length;
175 | for(;i= 128) {
17 | m = m.replace(k[l], "%u00" + j);
18 | }
19 | }
20 | }
21 | m = m.replace("%25", "%u0025").replace(/%/g, "\\");
22 | return m;
23 | };
24 | var a = function (n) {
25 | n = n.replace(/\\/g, "%").replace("%u0025", "%25");
26 | n = unescape(n.toString().replace(/%2B/g, "+"));
27 | var l = n.match(/(%u00([0-9A-F]{2}))/gi);
28 | if (l) {
29 | for (var m = 0; m < l.length; m++) {
30 | var k = l[m].substring(1, 3);
31 | var j = Number("0x" + k);
32 | if (j >= 128) {
33 | n = n.replace(l[m], k);
34 | }
35 | }
36 | }
37 | n = unescape(n.toString().replace(/%2B/g, "+"));
38 | return n;
39 | };
40 | var e = function (m) {
41 | var k, l, j, n;
42 | k = "";
43 | j = m.length;
44 | for (l = 0; l < j; l++) {
45 | n = m.charCodeAt(l);
46 | if ((n >= 1) && (n <= 127)) {
47 | k += m.charAt(l);
48 | } else {
49 | if (n > 2047) {
50 | k += String.fromCharCode(224 | ((n >> 12) & 15));
51 | k += String.fromCharCode(128 | ((n >> 6) & 63));
52 | k += String.fromCharCode(128 | ((n >> 0) & 63));
53 | } else {
54 | k += String.fromCharCode(192 | ((n >> 6) & 31));
55 | k += String.fromCharCode(128 | ((n >> 0) & 63));
56 | }
57 | }
58 | }
59 | return k;
60 | };
61 | var i = function (o) {
62 | var k, m, j, p;
63 | var n, l;
64 | k = "";
65 | j = o.length;
66 | m = 0;
67 | while (m < j) {
68 | p = o.charCodeAt(m++);
69 | switch (p >> 4) {
70 | case 0:
71 | case 1:
72 | case 2:
73 | case 3:
74 | case 4:
75 | case 5:
76 | case 6:
77 | case 7:
78 | k += o.charAt(m - 1);
79 | break;
80 | case 12:
81 | case 13:
82 | n = o.charCodeAt(m++);
83 | k += String.fromCharCode(((p & 31) << 6) | (n & 63));
84 | break;
85 | case 14:
86 | n = o.charCodeAt(m++);
87 | l = o.charCodeAt(m++);
88 | k += String.fromCharCode(((p & 15) << 12) | ((n & 63) << 6) | ((l & 63) << 0));
89 | break;
90 | }
91 | }
92 | return k;
93 | };
94 | var g = function (p) {
95 | var l, n, j;
96 | var o, m, k;
97 | j = p.length;
98 | n = 0;
99 | l = "";
100 | while (n < j) {
101 | o = p.charCodeAt(n++) & 255;
102 | if (n == j) {
103 | l += c.charAt(o >> 2);
104 | l += c.charAt((o & 3) << 4);
105 | l += "==";
106 | break;
107 | }
108 | m = p.charCodeAt(n++);
109 | if (n == j) {
110 | l += c.charAt(o >> 2);
111 | l += c.charAt(((o & 3) << 4) | ((m & 240) >> 4));
112 | l += c.charAt((m & 15) << 2);
113 | l += "=";
114 | break;
115 | }
116 | k = p.charCodeAt(n++);
117 | l += c.charAt(o >> 2);
118 | l += c.charAt(((o & 3) << 4) | ((m & 240) >> 4));
119 | l += c.charAt(((m & 15) << 2) | ((k & 192) >> 6));
120 | l += c.charAt(k & 63);
121 | }
122 | return l;
123 | };
124 | var b = function (q) {
125 | var p, o, m, k;
126 | var n, j, l;
127 | j = q.length;
128 | n = 0;
129 | l = "";
130 | while (n < j) {
131 | do {
132 | p = h[q.charCodeAt(n++) & 255];
133 | } while (n < j && p == -1);
134 | if (p == -1) {
135 | break;
136 | }
137 | do {
138 | o = h[q.charCodeAt(n++) & 255];
139 | } while (n < j && o == -1);
140 | if (o == -1) {
141 | break;
142 | }
143 | l += String.fromCharCode((p << 2) | ((o & 48) >> 4));
144 | do {
145 | m = q.charCodeAt(n++) & 255;
146 | if (m == 61) {
147 | return l;
148 | }
149 | m = h[m];
150 | } while (n < j && m == -1);
151 | if (m == -1) {
152 | break;
153 | }
154 | l += String.fromCharCode(((o & 15) << 4) | ((m & 60) >> 2));
155 | do {
156 | k = q.charCodeAt(n++) & 255;
157 | if (k == 61) {
158 | return l;
159 | }
160 | k = h[k];
161 | } while (n < j && k == -1);
162 | if (k == -1) {
163 | break;
164 | }
165 | l += String.fromCharCode(((m & 3) << 6) | k);
166 | }
167 | return l;
168 | };
169 | var d = function (m) {
170 | var k, l, j, n;
171 | k = "";
172 | j = m.length;
173 | for (l = 0; l < j; l++) {
174 | n = m.charCodeAt(l);
175 | if ((n >= 1) && (n <= 127)) {
176 | k += m.charAt(l);
177 | } else {
178 | if (n > 2047) {
179 | k += String.fromCharCode(224 | ((n >> 12) & 15));
180 | k += String.fromCharCode(128 | ((n >> 6) & 63));
181 | k += String.fromCharCode(128 | ((n >> 0) & 63));
182 | } else {
183 | k += String.fromCharCode(192 | ((n >> 6) & 31));
184 | k += String.fromCharCode(128 | ((n >> 0) & 63));
185 | }
186 | }
187 | }
188 | return k;
189 | };
190 | return {
191 | uniEncode: f,
192 | uniDecode: a,
193 | base64Encode: g,
194 | base64Decode: b,
195 | utf8Encode: e,
196 | utf8Decode: i,
197 | utf16to8: d
198 | };
199 |
200 | }(jQuery));
--------------------------------------------------------------------------------
/js/jsbeautify.js:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | JS Beautifier
4 | ---------------
5 | $Date: 2008-06-10 14:49:11 +0300 (Tue, 10 Jun 2008) $
6 | $Revision: 60 $
7 |
8 |
9 | Written by Einars "elfz" Lielmanis,
10 | http://elfz.laacz.lv/beautify/
11 |
12 | Originally converted to javascript by Vital,
13 | http://my.opera.com/Vital/blog/2007/11/21/javascript-beautify-on-javascript-translated
14 |
15 |
16 | You are free to use this in any way you want, in case you find this useful or working for you.
17 |
18 | Usage:
19 | js_beautify(js_source_text);
20 |
21 | */
22 |
23 |
24 | function jsbeautify(js_source_text, indent_size, indent_character, indent_level)
25 | {
26 |
27 | var input, output, token_text, last_type, last_text, last_word, current_mode, modes, indent_string;
28 | var whitespace, wordchar, punct, parser_pos, line_starters, in_case;
29 | var prefix, token_type, do_block_just_closed, var_line, var_line_tainted;
30 |
31 |
32 |
33 | function trim_output()
34 | {
35 | while (output.length && (output[output.length - 1] === ' ' || output[output.length - 1] === indent_string)) {
36 | output.pop();
37 | }
38 | }
39 |
40 | function print_newline(ignore_repeated)
41 | {
42 | ignore_repeated = typeof ignore_repeated === 'undefined' ? true : ignore_repeated;
43 |
44 | trim_output();
45 |
46 | if (!output.length) {
47 | return; // no newline on start of file
48 | }
49 |
50 | if (output[output.length - 1] !== "\n" || !ignore_repeated) {
51 | output.push("\n");
52 | }
53 | for (var i = 0; i < indent_level; i++) {
54 | output.push(indent_string);
55 | }
56 | }
57 |
58 |
59 |
60 | function print_space()
61 | {
62 | var last_output = output.length ? output[output.length - 1] : ' ';
63 | if (last_output !== ' ' && last_output !== '\n' && last_output !== indent_string) { // prevent occassional duplicate space
64 | output.push(' ');
65 | }
66 | }
67 |
68 |
69 | function print_token()
70 | {
71 | output.push(token_text);
72 | }
73 |
74 | function indent()
75 | {
76 | indent_level++;
77 | }
78 |
79 |
80 | function unindent()
81 | {
82 | if (indent_level) {
83 | indent_level--;
84 | }
85 | }
86 |
87 |
88 | function remove_indent()
89 | {
90 | if (output.length && output[output.length - 1] === indent_string) {
91 | output.pop();
92 | }
93 | }
94 |
95 |
96 | function set_mode(mode)
97 | {
98 | modes.push(current_mode);
99 | current_mode = mode;
100 | }
101 |
102 |
103 | function restore_mode()
104 | {
105 | do_block_just_closed = current_mode === 'DO_BLOCK';
106 | current_mode = modes.pop();
107 | }
108 |
109 |
110 | function in_array(what, arr)
111 | {
112 | for (var i = 0; i < arr.length; i++)
113 | {
114 | if (arr[i] === what) {
115 | return true;
116 | }
117 | }
118 | return false;
119 | }
120 |
121 |
122 |
123 | function get_next_token()
124 | {
125 | var n_newlines = 0;
126 | var c = '';
127 |
128 | do {
129 | if (parser_pos >= input.length) {
130 | return ['', 'TK_EOF'];
131 | }
132 | c = input.charAt(parser_pos);
133 |
134 | parser_pos += 1;
135 | if (c === "\n") {
136 | n_newlines += 1;
137 | }
138 | }
139 | while (in_array(c, whitespace));
140 |
141 | if (n_newlines > 1) {
142 | for (var i = 0; i < 2; i++) {
143 | print_newline(i === 0);
144 | }
145 | }
146 | var wanted_newline = (n_newlines === 1);
147 |
148 |
149 | if (in_array(c, wordchar)) {
150 | if (parser_pos < input.length) {
151 | while (in_array(input.charAt(parser_pos), wordchar)) {
152 | c += input.charAt(parser_pos);
153 | parser_pos += 1;
154 | if (parser_pos === input.length) {
155 | break;
156 | }
157 | }
158 | }
159 |
160 | // small and surprisingly unugly hack for 1E-10 representation
161 | if (parser_pos !== input.length && c.match(/^[0-9]+[Ee]$/) && input.charAt(parser_pos) === '-') {
162 | parser_pos += 1;
163 |
164 | var t = get_next_token(parser_pos);
165 | c += '-' + t[0];
166 | return [c, 'TK_WORD'];
167 | }
168 |
169 | if (c === 'in') { // hack for 'in' operator
170 | return [c, 'TK_OPERATOR'];
171 | }
172 | return [c, 'TK_WORD'];
173 | }
174 |
175 | if (c === '(' || c === '[') {
176 | return [c, 'TK_START_EXPR'];
177 | }
178 |
179 | if (c === ')' || c === ']') {
180 | return [c, 'TK_END_EXPR'];
181 | }
182 |
183 | if (c === '{') {
184 | return [c, 'TK_START_BLOCK'];
185 | }
186 |
187 | if (c === '}') {
188 | return [c, 'TK_END_BLOCK'];
189 | }
190 |
191 | if (c === ';') {
192 | return [c, 'TK_END_COMMAND'];
193 | }
194 |
195 | if (c === '/') {
196 | var comment = '';
197 | // peek for comment /* ... */
198 | if (input.charAt(parser_pos) === '*') {
199 | parser_pos += 1;
200 | if (parser_pos < input.length) {
201 | while (!(input.charAt(parser_pos) === '*' && input.charAt(parser_pos + 1) && input.charAt(parser_pos + 1) === '/') && parser_pos < input.length) {
202 | comment += input.charAt(parser_pos);
203 | parser_pos += 1;
204 | if (parser_pos >= input.length) {
205 | break;
206 | }
207 | }
208 | }
209 | parser_pos += 2;
210 | return ['/*' + comment + '*/', 'TK_BLOCK_COMMENT'];
211 | }
212 | // peek for comment // ...
213 | if (input.charAt(parser_pos) === '/') {
214 | comment = c;
215 | while (input.charAt(parser_pos) !== "\x0d" && input.charAt(parser_pos) !== "\x0a") {
216 | comment += input.charAt(parser_pos);
217 | parser_pos += 1;
218 | if (parser_pos >= input.length) {
219 | break;
220 | }
221 | }
222 | parser_pos += 1;
223 | if (wanted_newline) {
224 | print_newline();
225 | }
226 | return [comment, 'TK_COMMENT'];
227 | }
228 |
229 | }
230 |
231 | if (c === "'" || // string
232 | c === '"' || // string
233 | (c === '/' &&
234 | ((last_type === 'TK_WORD' && last_text === 'return') || (last_type === 'TK_START_EXPR' || last_type === 'TK_END_BLOCK' || last_type === 'TK_OPERATOR' || last_type === 'TK_EOF' || last_type === 'TK_END_COMMAND')))) { // regexp
235 | var sep = c;
236 | var esc = false;
237 | c = '';
238 |
239 | if (parser_pos < input.length) {
240 |
241 | while (esc || input.charAt(parser_pos) !== sep) {
242 | c += input.charAt(parser_pos);
243 | if (!esc) {
244 | esc = input.charAt(parser_pos) === '\\';
245 | } else {
246 | esc = false;
247 | }
248 | parser_pos += 1;
249 | if (parser_pos >= input.length) {
250 | break;
251 | }
252 | }
253 |
254 | }
255 |
256 | parser_pos += 1;
257 | if (last_type === 'TK_END_COMMAND') {
258 | print_newline();
259 | }
260 | return [sep + c + sep, 'TK_STRING'];
261 | }
262 |
263 | if (in_array(c, punct)) {
264 | while (parser_pos < input.length && in_array(c + input.charAt(parser_pos), punct)) {
265 | c += input.charAt(parser_pos);
266 | parser_pos += 1;
267 | if (parser_pos >= input.length) {
268 | break;
269 | }
270 | }
271 | return [c, 'TK_OPERATOR'];
272 | }
273 |
274 | return [c, 'TK_UNKNOWN'];
275 | }
276 |
277 |
278 | //----------------------------------
279 |
280 | indent_character = indent_character || ' ';
281 | indent_size = indent_size || 4;
282 |
283 | indent_string = '';
284 | while (indent_size--) {
285 | indent_string += indent_character;
286 | }
287 |
288 | input = js_source_text;
289 |
290 | last_word = ''; // last 'TK_WORD' passed
291 | last_type = 'TK_START_EXPR'; // last token type
292 | last_text = ''; // last token text
293 | output = [];
294 |
295 | do_block_just_closed = false;
296 | var_line = false;
297 | var_line_tainted = false;
298 |
299 | whitespace = "\n\r\t ".split('');
300 | wordchar = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$'.split('');
301 | punct = '+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> << >>> >>>= >>= <<= && &= | || ! !! , : ? ^ ^= |='.split(' ');
302 |
303 | // words which should always start on new line.
304 | line_starters = 'continue,try,throw,return,var,if,switch,case,default,for,while,break,function'.split(',');
305 |
306 | // states showing if we are currently in expression (i.e. "if" case) - 'EXPRESSION', or in usual block (like, procedure), 'BLOCK'.
307 | // some formatting depends on that.
308 | current_mode = 'BLOCK';
309 | modes = [current_mode];
310 |
311 | indent_level = indent_level || 0;
312 | parser_pos = 0; // parser position
313 | in_case = false; // flag for parser that case/default has been processed, and next colon needs special attention
314 | while (true) {
315 | var t = get_next_token(parser_pos);
316 | token_text = t[0];
317 | token_type = t[1];
318 | if (token_type === 'TK_EOF') {
319 | break;
320 | }
321 |
322 | switch (token_type) {
323 |
324 | case 'TK_START_EXPR':
325 | var_line = false;
326 | set_mode('EXPRESSION');
327 | if (last_type === 'TK_END_EXPR' || last_type === 'TK_START_EXPR') {
328 | // do nothing on (( and )( and ][ and ]( ..
329 | } else if (last_type !== 'TK_WORD' && last_type !== 'TK_OPERATOR') {
330 | print_space();
331 | } else if (in_array(last_word, line_starters) && last_word !== 'function') {
332 | print_space();
333 | }
334 | print_token();
335 | break;
336 |
337 | case 'TK_END_EXPR':
338 | print_token();
339 | restore_mode();
340 | break;
341 |
342 | case 'TK_START_BLOCK':
343 |
344 | if (last_word === 'do') {
345 | set_mode('DO_BLOCK');
346 | } else {
347 | set_mode('BLOCK');
348 | }
349 | if (last_type !== 'TK_OPERATOR' && last_type !== 'TK_START_EXPR') {
350 | if (last_type === 'TK_START_BLOCK') {
351 | print_newline();
352 | } else {
353 | print_space();
354 | }
355 | }
356 | print_token();
357 | indent();
358 | break;
359 |
360 | case 'TK_END_BLOCK':
361 | if (last_type === 'TK_START_BLOCK') {
362 | // nothing
363 | trim_output();
364 | unindent();
365 | } else {
366 | unindent();
367 | print_newline();
368 | }
369 | print_token();
370 | restore_mode();
371 | break;
372 |
373 | case 'TK_WORD':
374 |
375 | if (do_block_just_closed) {
376 | print_space();
377 | print_token();
378 | print_space();
379 | break;
380 | }
381 |
382 | if (token_text === 'case' || token_text === 'default') {
383 | if (last_text === ':') {
384 | // switch cases following one another
385 | remove_indent();
386 | } else {
387 | // case statement starts in the same line where switch
388 | unindent();
389 | print_newline();
390 | indent();
391 | }
392 | print_token();
393 | in_case = true;
394 | break;
395 | }
396 |
397 |
398 | prefix = 'NONE';
399 | if (last_type === 'TK_END_BLOCK') {
400 | if (!in_array(token_text.toLowerCase(), ['else', 'catch', 'finally'])) {
401 | prefix = 'NEWLINE';
402 | } else {
403 | prefix = 'SPACE';
404 | print_space();
405 | }
406 | } else if (last_type === 'TK_END_COMMAND' && (current_mode === 'BLOCK' || current_mode === 'DO_BLOCK')) {
407 | prefix = 'NEWLINE';
408 | } else if (last_type === 'TK_END_COMMAND' && current_mode === 'EXPRESSION') {
409 | prefix = 'SPACE';
410 | } else if (last_type === 'TK_WORD') {
411 | prefix = 'SPACE';
412 | } else if (last_type === 'TK_START_BLOCK') {
413 | prefix = 'NEWLINE';
414 | } else if (last_type === 'TK_END_EXPR') {
415 | print_space();
416 | prefix = 'NEWLINE';
417 | }
418 |
419 | if (last_type !== 'TK_END_BLOCK' && in_array(token_text.toLowerCase(), ['else', 'catch', 'finally'])) {
420 | print_newline();
421 | } else if (in_array(token_text, line_starters) || prefix === 'NEWLINE') {
422 | if (last_text === 'else') {
423 | // no need to force newline on else break
424 | print_space();
425 | } else if ((last_type === 'TK_START_EXPR' || last_text === '=') && token_text === 'function') {
426 | // no need to force newline on 'function': (function
427 | // DONOTHING
428 | } else if (last_type === 'TK_WORD' && (last_text === 'return' || last_text === 'throw')) {
429 | // no newline between 'return nnn'
430 | print_space();
431 | } else if (last_type !== 'TK_END_EXPR') {
432 | if ((last_type !== 'TK_START_EXPR' || token_text !== 'var') && last_text !== ':') {
433 | // no need to force newline on 'var': for (var x = 0...)
434 | if (token_text === 'if' && last_type === 'TK_WORD' && last_word === 'else') {
435 | // no newline for } else if {
436 | print_space();
437 | } else {
438 | print_newline();
439 | }
440 | }
441 | } else {
442 | if (in_array(token_text, line_starters) && last_text !== ')') {
443 | print_newline();
444 | }
445 | }
446 | } else if (prefix === 'SPACE') {
447 | print_space();
448 | }
449 | print_token();
450 | last_word = token_text;
451 |
452 | if (token_text === 'var') {
453 | var_line = true;
454 | var_line_tainted = false;
455 | }
456 |
457 | break;
458 |
459 | case 'TK_END_COMMAND':
460 |
461 | print_token();
462 | var_line = false;
463 | break;
464 |
465 | case 'TK_STRING':
466 |
467 | if (last_type === 'TK_START_BLOCK' || last_type === 'TK_END_BLOCK') {
468 | print_newline();
469 | } else if (last_type === 'TK_WORD') {
470 | print_space();
471 | }
472 | print_token();
473 | break;
474 |
475 | case 'TK_OPERATOR':
476 |
477 | var start_delim = true;
478 | var end_delim = true;
479 | if (var_line && token_text !== ',') {
480 | var_line_tainted = true;
481 | if (token_text === ':') {
482 | var_line = false;
483 | }
484 | }
485 |
486 | if (token_text === ':' && in_case) {
487 | print_token(); // colon really asks for separate treatment
488 | print_newline();
489 | break;
490 | }
491 |
492 | in_case = false;
493 |
494 | if (token_text === ',') {
495 | if (var_line) {
496 | if (var_line_tainted) {
497 | print_token();
498 | print_newline();
499 | var_line_tainted = false;
500 | } else {
501 | print_token();
502 | print_space();
503 | }
504 | } else if (last_type === 'TK_END_BLOCK') {
505 | print_token();
506 | print_newline();
507 | } else {
508 | if (current_mode === 'BLOCK') {
509 | print_token();
510 | print_newline();
511 | } else {
512 | // EXPR od DO_BLOCK
513 | print_token();
514 | print_space();
515 | }
516 | }
517 | break;
518 | } else if (token_text === '--' || token_text === '++') { // unary operators special case
519 | if (last_text === ';') {
520 | // space for (;; ++i)
521 | start_delim = true;
522 | end_delim = false;
523 | } else {
524 | start_delim = false;
525 | end_delim = false;
526 | }
527 | } else if (token_text === '!' && last_type === 'TK_START_EXPR') {
528 | // special case handling: if (!a)
529 | start_delim = false;
530 | end_delim = false;
531 | } else if (last_type === 'TK_OPERATOR') {
532 | start_delim = false;
533 | end_delim = false;
534 | } else if (last_type === 'TK_END_EXPR') {
535 | start_delim = true;
536 | end_delim = true;
537 | } else if (token_text === '.') {
538 | // decimal digits or object.property
539 | start_delim = false;
540 | end_delim = false;
541 |
542 | } else if (token_text === ':') {
543 | // zz: xx
544 | // can't differentiate ternary op, so for now it's a ? b: c; without space before colon
545 | if (last_text.match(/^\d+$/)) {
546 | // a little help for ternary a ? 1 : 0;
547 | start_delim = true;
548 | } else {
549 | start_delim = false;
550 | }
551 | }
552 | if (start_delim) {
553 | print_space();
554 | }
555 |
556 | print_token();
557 |
558 | if (end_delim) {
559 | print_space();
560 | }
561 | break;
562 |
563 | case 'TK_BLOCK_COMMENT':
564 |
565 | print_newline();
566 | print_token();
567 | print_newline();
568 | break;
569 |
570 | case 'TK_COMMENT':
571 |
572 | // print_newline();
573 | print_space();
574 | print_token();
575 | print_newline();
576 | break;
577 |
578 | case 'TK_UNKNOWN':
579 | print_token();
580 | break;
581 | }
582 |
583 | last_type = token_type;
584 | last_text = token_text;
585 | }
586 |
587 | return output.join('');
588 |
589 | }
590 |
--------------------------------------------------------------------------------
/js/popup.js:
--------------------------------------------------------------------------------
1 | $(function () {
2 | var rebuild = function () {
3 | var type = $("input[name=type]:checked").val();
4 | var mode = $("#mode option:selected").val();
5 | var inputobj = $("#inputtext");
6 | var inputtext = $("#inputtext").val();
7 | var outputobj = $("#outputtext");
8 | var result = "";
9 | try {
10 | switch (type) {
11 | case "qrcode":
12 | inputtext = inputtext.length == 0 && url.length > 0 ? url : inputtext;
13 | if (mode == 'auto') {
14 | if (clipboard.type == "file") {
15 | mode = 'qrdecode';
16 | } else {
17 | mode = 'qrencode';
18 | }
19 | }
20 | if (mode == 'qrdecode') {
21 | outputobj.show();
22 | result = "Decoding...";
23 | $("#qrcode").hide();
24 | var data = new FormData();
25 | data.append('upload_ctn', "on");
26 | data.append('url', inputtext);
27 | data.append('qrcode', clipboard.content);
28 | $.ajax({
29 | url: "http://tool.oschina.net/action/qrcode/decode",
30 | type: 'POST',
31 | data: data,
32 | dataType: 'json',
33 | contentType: false,
34 | enctype: 'multipart/form-data',
35 | processData: false,
36 | success: function (data) {
37 | if (data[0] != undefined) {
38 | outputobj.val(data[0].text);
39 | } else {
40 | outputobj.val("Decode failue");
41 | }
42 | }, error: function () {
43 | outputobj.val("An error occurred");
44 | }
45 | });
46 | } else {
47 | outputobj.hide();
48 | $("#qrcode").html('').show();
49 | $("#qrcode").qrcode({
50 | "render": "image",
51 | "size": 200,
52 | "color": "#3a3",
53 | "text": utf8text(inputtext)
54 | });
55 | if ($("#url").val().match(/taobao|tmall/)) {
56 | $('阿里妈妈推广').prependTo("#qrcode");
57 | }
58 | }
59 | break;
60 | case "url":
61 | var tounicode = function (text) {
62 | console.log(text);
63 | var result = "";
64 | for (var i = 0; i < text.length; i++) {
65 | var partial = text[i].charCodeAt(0).toString(16);
66 | while (partial.length !== 4)
67 | partial = "0" + partial;
68 | result += "\\u" + partial;
69 | }
70 | return result;
71 | };
72 | if (mode == 'auto') {
73 | if (inputtext.match(/^[0-9a-zA-Z\-_\*%\.]+$/)) {
74 | mode = 'urldecode';
75 | } else if (inputtext.match(/^\\u[0-9a-fA-F]{4}(.*)/)) {
76 | mode = 'unidecode';
77 | } else {
78 | mode = 'urlencode';
79 | }
80 | }
81 | switch (mode) {
82 | case "urlencode":
83 | result = encodeURIComponent(inputtext);
84 | break;
85 | case "urldecode":
86 | result = decodeURIComponent(inputtext);
87 | break;
88 | case "uniencode":
89 | result = tounicode(inputtext);
90 | break;
91 | case "unidecode":
92 | result = unescape(JSON.parse('"' + inputtext + '"'));
93 | break;
94 | default:
95 | result = inputtext;
96 | }
97 | break;
98 | case "timestamp":
99 | if (inputtext.length == 0 || inputtext.match(/^[0-9]{10,13}$/)) {
100 | var timeobj;
101 | if (inputtext.length == 0) {
102 | timeobj = new Date();
103 | } else if (inputtext.length == 10) {
104 | timeobj = new Date(parseInt(inputtext) * 1000);
105 | } else {
106 | timeobj = new Date(parseFloat(inputtext));
107 | }
108 | if (inputtext.length == 0) {
109 | inputobj.val(parseInt(timeobj.getTime() / 1000));
110 | }
111 | var year = timeobj.getFullYear();
112 | var month = timeobj.getMonth() + 1;
113 | var day = timeobj.getDate();
114 | var hours = timeobj.getHours();
115 | var minutes = timeobj.getMinutes();
116 | var seconds = timeobj.getSeconds();
117 | month = month < 10 ? "0" + month : month;
118 | day = day < 10 ? "0" + day : day;
119 | hours = hours < 10 ? "0" + hours : hours;
120 | minutes = minutes < 10 ? "0" + minutes : minutes;
121 | seconds = seconds < 10 ? "0" + seconds : seconds;
122 | result += year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
123 | } else if (inputtext.match(/^[0-9]{4}\-[0-9]{1,2}\-[0-9]{1,2}\s[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}$/)) {
124 | var timeobj = inputtext.replace(/(:|\s)/g, "-").split("-");
125 | result = parseInt(new Date(Date.UTC(timeobj[0], timeobj[1] - 1, timeobj[2], timeobj[3] - 8, timeobj[4], timeobj[5])).getTime() / 1000);
126 | } else {
127 | result = "Invalid format";
128 | }
129 | break;
130 | case "base64":
131 | console.log(clipboard);
132 | if (mode == "auto" && clipboard.type != "text" && clipboard.url.substring(0, 10) == 'data:image') {
133 | //result = clipboard.url.replace(/data:image\/([a-z]+);base64\,/, '');
134 | result = clipboard.url;
135 | } else {
136 | if (mode == 'auto') {
137 | if (clipboard != "text" || inputtext.match(/^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$/)) {
138 | mode = 'base64decode';
139 | } else {
140 | mode = 'base64encode';
141 | }
142 | }
143 | result = mode == 'base64encode' ? $.endecode.base64Encode($.endecode.utf8Encode(inputtext)) : $.endecode.utf8Decode($.endecode.base64Decode(inputtext));
144 | }
145 |
146 | break;
147 | case "translate":
148 | if (inputtext.length > 0) {
149 | clearTimeout(st);
150 | st = setTimeout(function () {
151 | var from = "auto";
152 | var to = "auto";
153 | if (/.*[\u4e00-\u9fa5]+.*$/.test(inputtext)) {
154 | to = "en";
155 | }
156 | if (mode !== 'auto') {
157 | var arr = mode.split('-');
158 | from = arr[0];
159 | to = arr[1];
160 | }
161 | to = to == "zh" ? "zh-CN" : to;
162 | var data = {
163 | client: "gtx",
164 | sl: from,
165 | tl: to,
166 | hl: "zh-CN",
167 | dj: 1,
168 | source: "icon",
169 | q: inputtext
170 | };
171 | $.ajax({
172 | url: "https://translate.google.cn/translate_a/single?dt=t&dt=bd",
173 | data: data,
174 | success: function (ret) {
175 | if (ret.sentences) {
176 | var arr = new Array();
177 | $.each(ret.sentences, function (i, j) {
178 | arr.push(j.trans);
179 | });
180 | result = arr.join('');
181 | } else if (ret.dict) {
182 | result = ret.dict[0].terms.join(",");
183 | } else {
184 | result = "无法翻译";
185 | }
186 | outputobj.val(result);
187 | }, error: function (ret) {
188 | result = "unknown format";
189 | }
190 | });
191 | }, 500);
192 | }
193 | break;
194 | case "format":
195 | if (mode == 'auto') {
196 | mode = "javascript";
197 | }
198 | switch (mode) {
199 | case "html":
200 | case "xml":
201 | case "sql":
202 | result = "Decoding...";
203 | $("#qrcode").hide();
204 | var data = new FormData();
205 | data.append(mode, inputtext);
206 | if (mode == "sql") {
207 | data.append("f" + mode, "");
208 | } else {
209 | data.append("sqlType", "mysql");
210 | }
211 | $.ajax({
212 | url: "http://tool.oschina.net/action/format/" + mode,
213 | type: 'POST',
214 | data: data,
215 | dataType: 'json',
216 | contentType: false,
217 | processData: false,
218 | success: function (data) {
219 | if (data["f" + mode] != undefined) {
220 | outputobj.val(data["f" + mode]);
221 | } else {
222 | outputobj.val("Format failue:" + data["msg"]);
223 | }
224 | }, error: function () {
225 | outputobj.val("An error occurred");
226 | }
227 | });
228 | break;
229 | case "json":
230 | try {
231 | var jsonobj = $.parseJSON(inputtext);
232 | var str = JSON.stringify(jsonobj, undefined, 4);
233 | result = str;
234 | } catch (e) {
235 | result = "An error occurred:" + e.message;
236 | }
237 | break;
238 | case "javascript":
239 | result = jsbeautify(inputtext, 4, '');
240 | break;
241 | case "css":
242 | var options = {
243 | indent: '\t'
244 | };
245 | result = cssbeautify(inputtext, options);
246 | break;
247 | }
248 | break;
249 | default:
250 | outputobj.val(inputtext);
251 | break;
252 | }
253 | } catch (e) {
254 | console.log(e);
255 | result = "An error occurred:" + e.message;
256 | }
257 | outputobj.val(result);
258 | };
259 |
260 | if ($('[data-toggle="select"]').length) {
261 | $('[data-toggle="select"]').select2();
262 | }
263 | $("#exchange").on("click", function () {
264 | $("#inputtext").val($("#outputtext").val());
265 | rebuild();
266 | });
267 | $("#inputtext").bind("input propertychange", function () {
268 | rebuild();
269 | });
270 | $("input[name=type]").on("click", function () {
271 | $("#mode").select2('data', []);
272 | $("#mode option").remove();
273 | var selectlist = $(this).data("select");
274 | $(selectlist.split("|")).each(function (i, j) {
275 | $("").appendTo($("#mode"));
276 | });
277 | $("#mode").select2('val', 'auto');
278 | if ($(this).val() == "qrcode") {
279 | $("#outputtext").hide();
280 | $("#qrcode").show();
281 | } else {
282 | $("#outputtext").show();
283 | $("#qrcode").hide();
284 | }
285 | rebuild();
286 | });
287 | $("#truncate").on("click", function () {
288 | $("#inputtext").val('').focus();
289 | clipboard.type = "text";
290 | clipboard.content = "";
291 | clipboard.url = "";
292 | rebuild();
293 | });
294 | $("#copy").on("click", function () {
295 | copy($("#outputtext").val());
296 | });
297 | $("#mode").change(function () {
298 | rebuild();
299 | });
300 | $(document).bind('paste', function (e) {
301 | var event = (e.clipboardData || e.originalEvent.clipboardData);
302 | var type = "type";
303 | var content = "";
304 | try {
305 | if (event.items[0].type === "text/plain") {
306 | type = "text";
307 | content = event.getData('text/plain');
308 | } else {
309 | type = "file";
310 | content = event.items[0].getAsFile();
311 | var reader = new FileReader();
312 | reader.onload = function (evt) {
313 | clipboard.url = evt.target.result;
314 | };
315 | reader.readAsDataURL(content);
316 | $("#inputtext").val("read file from clipboard");
317 | }
318 | clipboard.type = type;
319 | clipboard.content = content;
320 | } catch (exc) {
321 | console.log("An error occurred:" + e.message);
322 | }
323 | rebuild();
324 | });
325 |
326 | var pastetext = paste();
327 |
328 | chrome.tabs.query({
329 | currentWindow: true,
330 | active: true
331 | },
332 | function (tab) {
333 | url = tab[0].url;
334 | $("input[name=type][value=qrcode]").attr("checked", "checked");
335 | var inputtext = $("#inputtext");
336 | if (pastetext.match(/^[0-9]{10,13}$/)) {
337 | $("input[name=type][value=timestamp]").attr("checked", "checked");
338 | inputtext.val(pastetext).focus();
339 | } else if (clipboard.type == "text") {
340 | $("#url").val(url);
341 | if (($.trim(pastetext).length == 0 || !pastetext.match(/^[a-zA-Z0-9]{6,10}$/)) && url.match(/^((https|http|ftp)?:\/\/)(.*)/)) {
342 | pastetext = url;
343 | }
344 | inputtext.val(pastetext).focus();
345 | $("input[name=type][value=qrcode]").attr("checked", "checked");
346 | }
347 | $("input[name=type]:checked").click();
348 | });
349 |
350 | });
--------------------------------------------------------------------------------
/js/respond.min.js:
--------------------------------------------------------------------------------
1 | /*! Respond.js v1.4.2: min/max-width media query polyfill * Copyright 2013 Scott Jehl
2 | * Licensed under https://github.com/scottjehl/Respond/blob/master/LICENSE-MIT
3 | * */
4 |
5 | !function(a){"use strict";a.matchMedia=a.matchMedia||function(a){var b,c=a.documentElement,d=c.firstElementChild||c.firstChild,e=a.createElement("body"),f=a.createElement("div");return f.id="mq-test-1",f.style.cssText="position:absolute;top:-100em",e.style.background="none",e.appendChild(f),function(a){return f.innerHTML='',c.insertBefore(e,d),b=42===f.offsetWidth,c.removeChild(e),{matches:b,media:a}}}(a.document)}(this),function(a){"use strict";function b(){u(!0)}var c={};a.respond=c,c.update=function(){};var d=[],e=function(){var b=!1;try{b=new a.XMLHttpRequest}catch(c){b=new a.ActiveXObject("Microsoft.XMLHTTP")}return function(){return b}}(),f=function(a,b){var c=e();c&&(c.open("GET",a,!0),c.onreadystatechange=function(){4!==c.readyState||200!==c.status&&304!==c.status||b(c.responseText)},4!==c.readyState&&c.send(null))};if(c.ajax=f,c.queue=d,c.regex={media:/@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi,keyframes:/@(?:\-(?:o|moz|webkit)\-)?keyframes[^\{]+\{(?:[^\{\}]*\{[^\}\{]*\})+[^\}]*\}/gi,urls:/(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g,findStyles:/@media *([^\{]+)\{([\S\s]+?)$/,only:/(only\s+)?([a-zA-Z]+)\s?/,minw:/\([\s]*min\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/,maxw:/\([\s]*max\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/},c.mediaQueriesSupported=a.matchMedia&&null!==a.matchMedia("only all")&&a.matchMedia("only all").matches,!c.mediaQueriesSupported){var g,h,i,j=a.document,k=j.documentElement,l=[],m=[],n=[],o={},p=30,q=j.getElementsByTagName("head")[0]||k,r=j.getElementsByTagName("base")[0],s=q.getElementsByTagName("link"),t=function(){var a,b=j.createElement("div"),c=j.body,d=k.style.fontSize,e=c&&c.style.fontSize,f=!1;return b.style.cssText="position:absolute;font-size:1em;width:1em",c||(c=f=j.createElement("body"),c.style.background="none"),k.style.fontSize="100%",c.style.fontSize="100%",c.appendChild(b),f&&k.insertBefore(c,k.firstChild),a=b.offsetWidth,f?k.removeChild(c):c.removeChild(b),k.style.fontSize=d,e&&(c.style.fontSize=e),a=i=parseFloat(a)},u=function(b){var c="clientWidth",d=k[c],e="CSS1Compat"===j.compatMode&&d||j.body[c]||d,f={},o=s[s.length-1],r=(new Date).getTime();if(b&&g&&p>r-g)return a.clearTimeout(h),h=a.setTimeout(u,p),void 0;g=r;for(var v in l)if(l.hasOwnProperty(v)){var w=l[v],x=w.minw,y=w.maxw,z=null===x,A=null===y,B="em";x&&(x=parseFloat(x)*(x.indexOf(B)>-1?i||t():1)),y&&(y=parseFloat(y)*(y.indexOf(B)>-1?i||t():1)),w.hasquery&&(z&&A||!(z||e>=x)||!(A||y>=e))||(f[w.media]||(f[w.media]=[]),f[w.media].push(m[w.rules]))}for(var C in n)n.hasOwnProperty(C)&&n[C]&&n[C].parentNode===q&&q.removeChild(n[C]);n.length=0;for(var D in f)if(f.hasOwnProperty(D)){var E=j.createElement("style"),F=f[D].join("\n");E.type="text/css",E.media=D,q.insertBefore(E,o.nextSibling),E.styleSheet?E.styleSheet.cssText=F:E.appendChild(j.createTextNode(F)),n.push(E)}},v=function(a,b,d){var e=a.replace(c.regex.keyframes,"").match(c.regex.media),f=e&&e.length||0;b=b.substring(0,b.lastIndexOf("/"));var g=function(a){return a.replace(c.regex.urls,"$1"+b+"$2$3")},h=!f&&d;b.length&&(b+="/"),h&&(f=1);for(var i=0;f>i;i++){var j,k,n,o;h?(j=d,m.push(g(a))):(j=e[i].match(c.regex.findStyles)&&RegExp.$1,m.push(RegExp.$2&&g(RegExp.$2))),n=j.split(","),o=n.length;for(var p=0;o>p;p++)k=n[p],l.push({media:k.split("(")[0].match(c.regex.only)&&RegExp.$2||"all",rules:m.length-1,hasquery:k.indexOf("(")>-1,minw:k.match(c.regex.minw)&&parseFloat(RegExp.$1)+(RegExp.$2||""),maxw:k.match(c.regex.maxw)&&parseFloat(RegExp.$1)+(RegExp.$2||"")})}u()},w=function(){if(d.length){var b=d.shift();f(b.href,function(c){v(c,b.href,b.media),o[b.href]=!0,a.setTimeout(function(){w()},0)})}},x=function(){for(var b=0;b",
28 | "tabs",
29 | "*://*/*",
30 | "clipboardWrite",
31 | "clipboardRead"],
32 | "update_url": "https://clients2.google.com/service/update2/crx",
33 | "version": "1.0.1"
34 | }
35 |
--------------------------------------------------------------------------------
/popup.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Tiny tools
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
22 |
23 |
24 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------