1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-07-13 18:16:19 +02:00

prettify all src js files. Remove space rules from eslint

This commit is contained in:
Kushagra Gour
2017-07-04 02:47:49 +05:30
parent 95585c6274
commit ca1f255a34
12 changed files with 1100 additions and 593 deletions

View File

@ -34,7 +34,6 @@
"id-blacklist": "error",
"id-length": "off",
"id-match": "error",
"indent": ["error", "tab"],
"init-declarations": "off",
"jsx-quotes": "error",
@ -168,12 +167,6 @@
],
"sort-imports": "error",
"sort-vars": "off",
"space-before-blocks": "off",
"space-before-function-paren": "off",
"space-in-parens": ["error", "never"],
"space-infix-ops": "error",
"space-unary-ops": "error",
"spaced-comment": ["error", "always"],
"strict": ["error", "never"],
"template-curly-spacing": "error",
"unicode-bom": ["error", "never"],

View File

@ -1,19 +1,20 @@
/* global ga */
// eslint-disable-next-line max-params
window.trackEvent = function (category, action, label, value) {
window.trackEvent = function(category, action, label, value) {
if (window.DEBUG) {
utils.log('trackevent', category, action, label, value)
utils.log('trackevent', category, action, label, value);
return;
}
if (window.ga) {
ga('send', 'event', category, action, label, value);
}
}
};
// if online, load after sometime
if (navigator.onLine && !window.DEBUG) {
/* eslint-disable */
// prettier-ignore
setTimeout(function() {
(function(i,s,o,g,r,a,m){
i['GoogleAnalyticsObject']=r;

View File

@ -1,7 +1,7 @@
(function() {
window.deferred = function () {
window.deferred = function() {
var d = {};
var promise = new Promise(function (resolve, reject) {
var promise = new Promise(function(resolve, reject) {
d.resolve = resolve;
d.reject = reject;
});

View File

@ -12,8 +12,8 @@
}
function init() {
var dropdowns = $all('[dropdown]');
dropdowns.forEach(function (dropdown) {
dropdown.addEventListener('click', function (e) {
dropdowns.forEach(function(dropdown) {
dropdown.addEventListener('click', function(e) {
closeOpenDropdown(e.currentTarget);
e.currentTarget.classList.toggle('open');
openDropdown = e.currentTarget;
@ -21,7 +21,7 @@
});
});
document.addEventListener('click', function () {
document.addEventListener('click', function() {
closeOpenDropdown();
});
}

View File

@ -5,30 +5,37 @@ function openApp() {
});
}
chrome.browserAction.onClicked.addListener(function(){
chrome.browserAction.onClicked.addListener(function() {
openApp();
});
// Listen for tabs getting created.
chrome.tabs.onCreated.addListener(function (tab) {
chrome.tabs.onCreated.addListener(function(tab) {
// If a new tab is opened (without any URL), check user's
// replace Tab setting and act accordingly. Default is false.
if (tab.url === 'chrome://newtab/') {
chrome.storage.sync.get({
replaceNewTab: false
}, function(items) {
if (items.replaceNewTab) {
chrome.tabs.update(tab.id, {
url: chrome.extension.getURL('index.html')
}, function callback() {
console.log('ho gaya');
});
chrome.storage.sync.get(
{
replaceNewTab: false
},
function(items) {
if (items.replaceNewTab) {
chrome.tabs.update(
tab.id,
{
url: chrome.extension.getURL('index.html')
},
function callback() {
console.log('ho gaya');
}
);
}
}
});
);
}
});
chrome.runtime.onInstalled.addListener(function callback (details) {
chrome.runtime.onInstalled.addListener(function callback(details) {
if (details.reason === 'install') {
openApp();
}

View File

@ -1,27 +1,130 @@
window.jsLibs = [
{ url: 'https://code.jquery.com/jquery-3.2.1.min.js', label: 'jQuery', type: 'js' },
{ url: 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', label: 'Bootstrap 3', type: 'js' },
{ url: 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js', label: 'Bootstrap 4α', type: 'js' },
{ url: 'https://cdnjs.cloudflare.com/ajax/libs/foundation/6.3.1/js/foundation.min.js', label: 'Foundation', type: 'js' },
{ url: 'https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js', label: 'Angular', type: 'js' },
{ url: 'https://cdnjs.cloudflare.com/ajax/libs/react/15.5.4/react.min.js', label: 'React', type: 'js' },
{ url: 'https://cdnjs.cloudflare.com/ajax/libs/react/15.5.4/react-dom.min.js', label: 'React DOM', type: 'js' },
{ url: 'https://unpkg.com/vue@2.3.3/dist/vue.min.js', label: 'Vue.js', type: 'js' },
{ url: 'https://cdnjs.cloudflare.com/ajax/libs/three.js/85/three.min.js', label: 'Three.js', type: 'js' },
{ url: 'https://cdnjs.cloudflare.com/ajax/libs/d3/4.9.1/d3.min.js', label: 'D3', type: 'js' },
{ url: 'https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js', label: 'Underscore', type: 'js' },
{ url: 'https://cdnjs.cloudflare.com/ajax/libs/gsap/1.19.1/TweenMax.min.js', label: 'Greensock TweenMax', type: 'js' },
{ url: 'https://cdnjs.cloudflare.com/ajax/libs/uikit/2.27.4/js/uikit.min.js', label: 'UIkit 2', type: 'js' },
{ url: 'https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-beta.25/js/uikit.min.js', label: 'UIkit 3', type: 'js' },
{
url: 'https://code.jquery.com/jquery-3.2.1.min.js',
label: 'jQuery',
type: 'js'
},
{
url: 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js',
label: 'Bootstrap 3',
type: 'js'
},
{
url:
'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js',
label: 'Bootstrap 4α',
type: 'js'
},
{
url:
'https://cdnjs.cloudflare.com/ajax/libs/foundation/6.3.1/js/foundation.min.js',
label: 'Foundation',
type: 'js'
},
{
url: 'https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js',
label: 'Angular',
type: 'js'
},
{
url: 'https://cdnjs.cloudflare.com/ajax/libs/react/15.5.4/react.min.js',
label: 'React',
type: 'js'
},
{
url: 'https://cdnjs.cloudflare.com/ajax/libs/react/15.5.4/react-dom.min.js',
label: 'React DOM',
type: 'js'
},
{
url: 'https://unpkg.com/vue@2.3.3/dist/vue.min.js',
label: 'Vue.js',
type: 'js'
},
{
url: 'https://cdnjs.cloudflare.com/ajax/libs/three.js/85/three.min.js',
label: 'Three.js',
type: 'js'
},
{
url: 'https://cdnjs.cloudflare.com/ajax/libs/d3/4.9.1/d3.min.js',
label: 'D3',
type: 'js'
},
{
url:
'https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js',
label: 'Underscore',
type: 'js'
},
{
url: 'https://cdnjs.cloudflare.com/ajax/libs/gsap/1.19.1/TweenMax.min.js',
label: 'Greensock TweenMax',
type: 'js'
},
{
url: 'https://cdnjs.cloudflare.com/ajax/libs/uikit/2.27.4/js/uikit.min.js',
label: 'UIkit 2',
type: 'js'
},
{
url:
'https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-beta.25/js/uikit.min.js',
label: 'UIkit 3',
type: 'js'
}
];
window.cssLibs = [
{ url: 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css', label: 'Bootstrap 3', type: 'css' },
{ url: 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css', label: 'Bootstrap 4α', type: 'css' },
{ url: 'https://cdnjs.cloudflare.com/ajax/libs/bulma/0.4.2/css/bulma.min.css', label: 'Bulma', type: 'css' },
{ url: 'https://cdnjs.cloudflare.com/ajax/libs/foundation/6.3.1/css/foundation.min.css', label: 'Foundation', type: 'css' },
{ url: 'https://cdnjs.cloudflare.com/ajax/libs/hint.css/2.5.0/hint.min.css', label: 'Hint.css', type: 'css' },
{ url: 'https://cdnjs.cloudflare.com/ajax/libs/uikit/2.27.4/css/uikit.min.css', label: 'UIkit 2', type: 'css' },
{ url: 'https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-beta.25/css/uikit.min.css', label: 'UIkit 3', type: 'css' },
{ url: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css', label: 'Animate.css', type: 'css' },
{ url: 'https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css', label: 'FontAwesome', type: 'css' },
{
url:
'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css',
label: 'Bootstrap 3',
type: 'css'
},
{
url:
'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css',
label: 'Bootstrap 4α',
type: 'css'
},
{
url: 'https://cdnjs.cloudflare.com/ajax/libs/bulma/0.4.2/css/bulma.min.css',
label: 'Bulma',
type: 'css'
},
{
url:
'https://cdnjs.cloudflare.com/ajax/libs/foundation/6.3.1/css/foundation.min.css',
label: 'Foundation',
type: 'css'
},
{
url: 'https://cdnjs.cloudflare.com/ajax/libs/hint.css/2.5.0/hint.min.css',
label: 'Hint.css',
type: 'css'
},
{
url:
'https://cdnjs.cloudflare.com/ajax/libs/uikit/2.27.4/css/uikit.min.css',
label: 'UIkit 2',
type: 'css'
},
{
url:
'https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-beta.25/css/uikit.min.css',
label: 'UIkit 3',
type: 'css'
},
{
url:
'https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css',
label: 'Animate.css',
type: 'css'
},
{
url:
'https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css',
label: 'FontAwesome',
type: 'css'
}
];

View File

@ -1,16 +1,14 @@
(function(w) {
window.loadJS = function(src) {
var d = deferred();
var ref = w.document.getElementsByTagName("script")[0];
var script = w.document.createElement("script");
var ref = w.document.getElementsByTagName('script')[0];
var script = w.document.createElement('script');
script.src = src;
script.async = true;
ref.parentNode.insertBefore(script, ref);
script.onload = function () {
script.onload = function() {
d.resolve();
};
return d.promise;
};
})(window);

View File

@ -1,5 +1,4 @@
(function () {
(function() {
var noticationContainerEL = $('#js-alerts-container');
function addNotification(msg) {
@ -9,12 +8,12 @@
noticationContainerEL.textContent = msg;
noticationContainerEL.classList.add('is-active');
setTimeout(function () {
setTimeout(function() {
noticationContainerEL.classList.remove('is-active');
}, 2000)
}, 2000);
}
window.alertsService = {
add: addNotification
}
};
})();

View File

@ -1,32 +1,38 @@
// Restores preferences from chrome.storage.
function restoreOptions() {
chrome.storage.sync.get({
preserveLastCode: true,
replaceNewTab: false
}, function(items) {
document.forms.optionsForm.preserveLastCode.checked = items.preserveLastCode;
document.forms.optionsForm.replaceNewTab.checked = items.replaceNewTab;
});
chrome.storage.sync.get(
{
preserveLastCode: true,
replaceNewTab: false
},
function(items) {
document.forms.optionsForm.preserveLastCode.checked =
items.preserveLastCode;
document.forms.optionsForm.replaceNewTab.checked = items.replaceNewTab;
}
);
}
function saveOptions(e) {
var preserveLastCode = document.forms.optionsForm.preserveLastCode.checked;
var replaceNewTab = document.forms.optionsForm.replaceNewTab.checked;
chrome.storage.sync.set({
preserveLastCode: preserveLastCode,
replaceNewTab: replaceNewTab
}, function() {
var status = document.getElementById('js-status');
status.textContent = 'Settings saved.';
setTimeout(function() {
status.innerHTML = ' ';
}, 750);
});
chrome.storage.sync.set(
{
preserveLastCode: preserveLastCode,
replaceNewTab: replaceNewTab
},
function() {
var status = document.getElementById('js-status');
status.textContent = 'Settings saved.';
setTimeout(function() {
status.innerHTML = ' ';
}, 750);
}
);
e.preventDefault();
}
document.addEventListener('DOMContentLoaded', restoreOptions);
document.forms.optionsForm.addEventListener('submit',
saveOptions);
document.forms.optionsForm.addEventListener('submit', saveOptions);

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,7 @@
// textarea-autocomplete.js
(function() {
class TextareaAutoComplete {
constructor (textarea, filter) {
constructor(textarea, filter) {
this.t = textarea;
this.filter = filter;
var wrap = document.createElement('div');
@ -28,12 +26,12 @@
document.body.appendChild(this.list);
this.list.style.position = 'fixed';
});
},100);
}, 100);
this.t.addEventListener('input', (e) => this.onInput(e));
this.t.addEventListener('keydown', (e) => this.onKeyDown(e));
this.t.addEventListener('blur', (e) => this.closeSuggestions(e));
this.list.addEventListener('mousedown', (e) => this.onListMouseDown(e));
this.t.addEventListener('input', e => this.onInput(e));
this.t.addEventListener('keydown', e => this.onKeyDown(e));
this.t.addEventListener('blur', e => this.closeSuggestions(e));
this.list.addEventListener('mousedown', e => this.onListMouseDown(e));
}
get currentLineNumber() {
@ -49,24 +47,28 @@
}
getList(input) {
var url = 'https://api.cdnjs.com/libraries?search=';
return fetch(url + input)
.then((response) => {
return response.json().then((json) => json.results);
});
return fetch(url + input).then(response => {
return response.json().then(json => json.results);
});
}
replaceCurrentLine(val) {
var lines = this.t.value.split('\n');
lines.splice(this.currentLineNumber - 1, 1, val)
lines.splice(this.currentLineNumber - 1, 1, val);
this.t.value = lines.join('\n');
}
onInput() {
var currentLine = this.currentLine;
if (currentLine) {
if (currentLine.indexOf('/') !== -1 || currentLine.match(/https*:\/\//)) { return; }
if (
currentLine.indexOf('/') !== -1 ||
currentLine.match(/https*:\/\//)
) {
return;
}
clearTimeout(this.timeout);
this.timeout = setTimeout(() => {
this.loader.style.display = 'block';
this.getList(currentLine).then((arr) => {
this.getList(currentLine).then(arr => {
this.loader.style.display = 'none';
if (!arr.length) {
this.closeSuggestions();
@ -74,12 +76,13 @@
}
this.list.innerHTML = '';
if (this.filter) {
/* eslint-disable no-param-reassign */
arr = arr.filter(this.filter);
}
for (var i = 0; i < Math.min(arr.length, 10); i++) {
this.list.innerHTML += `<li data-url="${arr[i].latest}"><a>${arr[i].name}</a></li>`;
this.list.innerHTML += `<li data-url="${arr[i].latest}"><a>${arr[
i
].name}</a></li>`;
}
this.isShowingSuggestions = true;
if (!this.textareaBounds) {
@ -95,7 +98,9 @@
}
onKeyDown(event) {
var selectedItemElement;
if (!this.isShowingSuggestions) { return; }
if (!this.isShowingSuggestions) {
return;
}
if (event.keyCode === 27) {
this.closeSuggestions();
@ -123,19 +128,18 @@
event.preventDefault();
} else if (event.keyCode === 13 && this.isShowingSuggestions) {
selectedItemElement = this.list.querySelector('.selected');
this.replaceCurrentLine(selectedItemElement.dataset.url)
this.replaceCurrentLine(selectedItemElement.dataset.url);
this.closeSuggestions();
}
}
onListMouseDown(event) {
var target = event.target;
if (target.parentElement.dataset.url) {
this.replaceCurrentLine(target.parentElement.dataset.url)
this.replaceCurrentLine(target.parentElement.dataset.url);
this.closeSuggestions();
}
}
}
window.TextareaAutoComplete = TextareaAutoComplete;
})();

View File

@ -1,9 +1,10 @@
(function () {
(function() {
window.DEBUG = document.cookie.indexOf('wmdebug') > -1;
window.$ = document.querySelector.bind(document);
window.$all = (selector) => [...document.querySelectorAll(selector)];
var alphaNum = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
window.$all = selector => [...document.querySelectorAll(selector)];
var alphaNum =
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
/**
* The following 2 functions are supposed to find the next/previous sibling until the
@ -13,7 +14,7 @@
* @param Selector that should match for next siblings
* @return element Next element that mathes `selector`
*/
Node.prototype.nextUntil = function (selector) {
Node.prototype.nextUntil = function(selector) {
const siblings = [...this.parentNode.querySelectorAll(selector)];
const index = siblings.indexOf(this);
return siblings[index + 1];
@ -23,7 +24,7 @@
* @param Selector that should match for next siblings
* @return element Next element that mathes `selector`
*/
Node.prototype.previousUntil = function (selector) {
Node.prototype.previousUntil = function(selector) {
const siblings = [...this.parentNode.querySelectorAll(selector)];
const index = siblings.indexOf(this);
return siblings[index - 1];
@ -36,10 +37,18 @@
for (var i = 0; i < 3; i++) {
var na = Number(pa[i]);
var nb = Number(pb[i]);
if (na > nb) { return 1; }
if (nb > na) { return -1; }
if (!isNaN(na) && isNaN(nb)) { return 1; }
if (isNaN(na) && !isNaN(nb)) { return -1; }
if (na > nb) {
return 1;
}
if (nb > na) {
return -1;
}
if (!isNaN(na) && isNaN(nb)) {
return 1;
}
if (isNaN(na) && !isNaN(nb)) {
return -1;
}
}
return 0;
}
@ -47,7 +56,7 @@
function generateRandomId(len) {
var length = len || 10;
var id = '';
for (var i = length; i--;) {
for (var i = length; i--; ) {
id += alphaNum[~~(Math.random() * alphaNum.length)];
}
return id;
@ -75,43 +84,53 @@
var loopId = 1;
var patches = [];
var varPrefix = '_wmloopvar';
var varStr = 'var %d = Date.now();\n'
var checkStr = '\nif (Date.now() - %d > 1000) { window.top.previewException(new Error("Infinite loop")); break;}\n'
var varStr = 'var %d = Date.now();\n';
var checkStr =
'\nif (Date.now() - %d > 1000) { window.top.previewException(new Error("Infinite loop")); break;}\n';
esprima.parse(code, { tolerant: true, range: true, jsx: true }, function (node) {
esprima.parse(code, { tolerant: true, range: true, jsx: true }, function(
node
) {
switch (node.type) {
case 'DoWhileStatement':
case 'ForStatement':
case 'ForInStatement':
case 'ForOfStatement':
case 'WhileStatement':
var start = 1 + node.body.range[0];
var end = node.body.range[1];
var prolog = checkStr.replace('%d', varPrefix + loopId);
var epilog = '';
case 'DoWhileStatement':
case 'ForStatement':
case 'ForInStatement':
case 'ForOfStatement':
case 'WhileStatement':
var start = 1 + node.body.range[0];
var end = node.body.range[1];
var prolog = checkStr.replace('%d', varPrefix + loopId);
var epilog = '';
if (node.body.type !== 'BlockStatement') {
// `while(1) doThat()` becomes `while(1) {doThat()}`
prolog = '{' + prolog;
epilog = '}';
--start;
}
if (node.body.type !== 'BlockStatement') {
// `while(1) doThat()` becomes `while(1) {doThat()}`
prolog = '{' + prolog;
epilog = '}';
--start;
}
patches.push({ pos: start, str: prolog });
patches.push({ pos: end, str: epilog });
patches.push({ pos: node.range[0], str: varStr.replace('%d', varPrefix + loopId) });
++loopId;
break;
patches.push({ pos: start, str: prolog });
patches.push({ pos: end, str: epilog });
patches.push({
pos: node.range[0],
str: varStr.replace('%d', varPrefix + loopId)
});
++loopId;
break;
default:
break;
default:
break;
}
});
/* eslint-disable no-param-reassign */
patches.sort(function (a, b) { return b.pos - a.pos }).forEach(function (patch) {
code = code.slice(0, patch.pos) + patch.str + code.slice(patch.pos);
});
patches
.sort(function(a, b) {
return b.pos - a.pos;
})
.forEach(function(patch) {
code = code.slice(0, patch.pos) + patch.str + code.slice(patch.pos);
});
/* eslint-disable no-param-reassign */
return code;
@ -119,9 +138,25 @@
function getHumanDate(timestamp) {
var d = new Date(timestamp);
var retVal = d.getDate() + ' '
+ [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][d.getMonth()] + ' '
+ d.getFullYear();
var retVal =
d.getDate() +
' ' +
[
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
][d.getMonth()] +
' ' +
d.getFullYear();
return retVal;
}
@ -134,7 +169,6 @@
// call handler
return callback(e);
});
}
window.utils = {