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-blacklist": "error",
"id-length": "off", "id-length": "off",
"id-match": "error", "id-match": "error",
"indent": ["error", "tab"],
"init-declarations": "off", "init-declarations": "off",
"jsx-quotes": "error", "jsx-quotes": "error",
@ -168,12 +167,6 @@
], ],
"sort-imports": "error", "sort-imports": "error",
"sort-vars": "off", "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"], "strict": ["error", "never"],
"template-curly-spacing": "error", "template-curly-spacing": "error",
"unicode-bom": ["error", "never"], "unicode-bom": ["error", "never"],

View File

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

View File

@ -14,17 +14,24 @@ chrome.tabs.onCreated.addListener(function (tab) {
// If a new tab is opened (without any URL), check user's // If a new tab is opened (without any URL), check user's
// replace Tab setting and act accordingly. Default is false. // replace Tab setting and act accordingly. Default is false.
if (tab.url === 'chrome://newtab/') { if (tab.url === 'chrome://newtab/') {
chrome.storage.sync.get({ chrome.storage.sync.get(
{
replaceNewTab: false replaceNewTab: false
}, function(items) { },
function(items) {
if (items.replaceNewTab) { if (items.replaceNewTab) {
chrome.tabs.update(tab.id, { chrome.tabs.update(
tab.id,
{
url: chrome.extension.getURL('index.html') url: chrome.extension.getURL('index.html')
}, function callback() { },
function callback() {
console.log('ho gaya'); console.log('ho gaya');
});
} }
}); );
}
}
);
} }
}); });

View File

@ -1,27 +1,130 @@
window.jsLibs = [ 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://code.jquery.com/jquery-3.2.1.min.js',
{ url: 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js', label: 'Bootstrap 4α', type: 'js' }, label: 'jQuery',
{ url: 'https://cdnjs.cloudflare.com/ajax/libs/foundation/6.3.1/js/foundation.min.js', label: 'Foundation', type: 'js' }, 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://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js',
{ url: 'https://unpkg.com/vue@2.3.3/dist/vue.min.js', label: 'Vue.js', type: 'js' }, label: 'Bootstrap 3',
{ url: 'https://cdnjs.cloudflare.com/ajax/libs/three.js/85/three.min.js', label: 'Three.js', type: '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:
{ url: 'https://cdnjs.cloudflare.com/ajax/libs/uikit/2.27.4/js/uikit.min.js', label: 'UIkit 2', type: 'js' }, 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js',
{ url: 'https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-beta.25/js/uikit.min.js', label: 'UIkit 3', type: '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 = [ 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:
{ url: 'https://cdnjs.cloudflare.com/ajax/libs/bulma/0.4.2/css/bulma.min.css', label: 'Bulma', type: 'css' }, 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css',
{ url: 'https://cdnjs.cloudflare.com/ajax/libs/foundation/6.3.1/css/foundation.min.css', label: 'Foundation', type: 'css' }, label: 'Bootstrap 3',
{ url: 'https://cdnjs.cloudflare.com/ajax/libs/hint.css/2.5.0/hint.min.css', label: 'Hint.css', type: '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:
{ url: 'https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css', label: 'FontAwesome', type: 'css' }, '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,9 +1,8 @@
(function(w) { (function(w) {
window.loadJS = function(src) { window.loadJS = function(src) {
var d = deferred(); var d = deferred();
var ref = w.document.getElementsByTagName("script")[0]; var ref = w.document.getElementsByTagName('script')[0];
var script = w.document.createElement("script"); var script = w.document.createElement('script');
script.src = src; script.src = src;
script.async = true; script.async = true;
ref.parentNode.insertBefore(script, ref); ref.parentNode.insertBefore(script, ref);
@ -12,5 +11,4 @@
}; };
return d.promise; return d.promise;
}; };
})(window); })(window);

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -2,8 +2,9 @@
window.DEBUG = document.cookie.indexOf('wmdebug') > -1; window.DEBUG = document.cookie.indexOf('wmdebug') > -1;
window.$ = document.querySelector.bind(document); window.$ = document.querySelector.bind(document);
window.$all = (selector) => [...document.querySelectorAll(selector)]; window.$all = selector => [...document.querySelectorAll(selector)];
var alphaNum = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; var alphaNum =
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
/** /**
* The following 2 functions are supposed to find the next/previous sibling until the * The following 2 functions are supposed to find the next/previous sibling until the
@ -36,10 +37,18 @@
for (var i = 0; i < 3; i++) { for (var i = 0; i < 3; i++) {
var na = Number(pa[i]); var na = Number(pa[i]);
var nb = Number(pb[i]); var nb = Number(pb[i]);
if (na > nb) { return 1; } if (na > nb) {
if (nb > na) { return -1; } return 1;
if (!isNaN(na) && isNaN(nb)) { return 1; } }
if (isNaN(na) && !isNaN(nb)) { return -1; } if (nb > na) {
return -1;
}
if (!isNaN(na) && isNaN(nb)) {
return 1;
}
if (isNaN(na) && !isNaN(nb)) {
return -1;
}
} }
return 0; return 0;
} }
@ -75,10 +84,13 @@
var loopId = 1; var loopId = 1;
var patches = []; var patches = [];
var varPrefix = '_wmloopvar'; var varPrefix = '_wmloopvar';
var varStr = 'var %d = Date.now();\n' var varStr = 'var %d = Date.now();\n';
var checkStr = '\nif (Date.now() - %d > 1000) { window.top.previewException(new Error("Infinite loop")); break;}\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) { switch (node.type) {
case 'DoWhileStatement': case 'DoWhileStatement':
case 'ForStatement': case 'ForStatement':
@ -99,7 +111,10 @@
patches.push({ pos: start, str: prolog }); patches.push({ pos: start, str: prolog });
patches.push({ pos: end, str: epilog }); patches.push({ pos: end, str: epilog });
patches.push({ pos: node.range[0], str: varStr.replace('%d', varPrefix + loopId) }); patches.push({
pos: node.range[0],
str: varStr.replace('%d', varPrefix + loopId)
});
++loopId; ++loopId;
break; break;
@ -109,7 +124,11 @@
}); });
/* eslint-disable no-param-reassign */ /* eslint-disable no-param-reassign */
patches.sort(function (a, b) { return b.pos - a.pos }).forEach(function (patch) { 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); code = code.slice(0, patch.pos) + patch.str + code.slice(patch.pos);
}); });
@ -119,9 +138,25 @@
function getHumanDate(timestamp) { function getHumanDate(timestamp) {
var d = new Date(timestamp); var d = new Date(timestamp);
var retVal = d.getDate() + ' ' var retVal =
+ [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][d.getMonth()] + ' ' d.getDate() +
+ d.getFullYear(); ' ' +
[
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
][d.getMonth()] +
' ' +
d.getFullYear();
return retVal; return retVal;
} }
@ -134,7 +169,6 @@
// call handler // call handler
return callback(e); return callback(e);
}); });
} }
window.utils = { window.utils = {