mirror of
https://github.com/chinchang/web-maker.git
synced 2025-07-13 10:06:23 +02:00
prettify all src js files. Remove space rules from eslint
This commit is contained in:
@ -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"],
|
||||||
|
@ -1,19 +1,20 @@
|
|||||||
/* global ga */
|
/* global ga */
|
||||||
// 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;
|
||||||
@ -29,4 +30,4 @@ if (navigator.onLine && !window.DEBUG) {
|
|||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
/* eslint-enable */
|
/* eslint-enable */
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
(function() {
|
(function() {
|
||||||
window.deferred = function () {
|
window.deferred = function() {
|
||||||
var d = {};
|
var d = {};
|
||||||
var promise = new Promise(function (resolve, reject) {
|
var promise = new Promise(function(resolve, reject) {
|
||||||
d.resolve = resolve;
|
d.resolve = resolve;
|
||||||
d.reject = reject;
|
d.reject = reject;
|
||||||
});
|
});
|
||||||
@ -9,4 +9,4 @@
|
|||||||
d.promise = promise;
|
d.promise = promise;
|
||||||
return Object.assign(d, promise);
|
return Object.assign(d, promise);
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
}
|
}
|
||||||
function init() {
|
function init() {
|
||||||
var dropdowns = $all('[dropdown]');
|
var dropdowns = $all('[dropdown]');
|
||||||
dropdowns.forEach(function (dropdown) {
|
dropdowns.forEach(function(dropdown) {
|
||||||
dropdown.addEventListener('click', function (e) {
|
dropdown.addEventListener('click', function(e) {
|
||||||
closeOpenDropdown(e.currentTarget);
|
closeOpenDropdown(e.currentTarget);
|
||||||
e.currentTarget.classList.toggle('open');
|
e.currentTarget.classList.toggle('open');
|
||||||
openDropdown = e.currentTarget;
|
openDropdown = e.currentTarget;
|
||||||
@ -21,10 +21,10 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener('click', function () {
|
document.addEventListener('click', function() {
|
||||||
closeOpenDropdown();
|
closeOpenDropdown();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
init();
|
init();
|
||||||
})($all);
|
})($all);
|
||||||
|
@ -5,30 +5,37 @@ function openApp() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.browserAction.onClicked.addListener(function(){
|
chrome.browserAction.onClicked.addListener(function() {
|
||||||
openApp();
|
openApp();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Listen for tabs getting created.
|
// 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
|
// 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
|
{
|
||||||
}, function(items) {
|
replaceNewTab: false
|
||||||
if (items.replaceNewTab) {
|
},
|
||||||
chrome.tabs.update(tab.id, {
|
function(items) {
|
||||||
url: chrome.extension.getURL('index.html')
|
if (items.replaceNewTab) {
|
||||||
}, function callback() {
|
chrome.tabs.update(
|
||||||
console.log('ho gaya');
|
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') {
|
if (details.reason === 'install') {
|
||||||
openApp();
|
openApp();
|
||||||
}
|
}
|
||||||
@ -39,4 +46,4 @@ chrome.runtime.onInstalled.addListener(function callback (details) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
chrome.runtime.setUninstallURL('https://webmakerapp.com/uninstall/');
|
chrome.runtime.setUninstallURL('https://webmakerapp.com/uninstall/');
|
||||||
|
@ -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'
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
@ -1,16 +1,14 @@
|
|||||||
(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);
|
||||||
script.onload = function () {
|
script.onload = function() {
|
||||||
d.resolve();
|
d.resolve();
|
||||||
};
|
};
|
||||||
return d.promise;
|
return d.promise;
|
||||||
};
|
};
|
||||||
|
})(window);
|
||||||
})(window);
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
(function () {
|
(function() {
|
||||||
|
|
||||||
var noticationContainerEL = $('#js-alerts-container');
|
var noticationContainerEL = $('#js-alerts-container');
|
||||||
|
|
||||||
function addNotification(msg) {
|
function addNotification(msg) {
|
||||||
@ -9,12 +8,12 @@
|
|||||||
noticationContainerEL.textContent = msg;
|
noticationContainerEL.textContent = msg;
|
||||||
noticationContainerEL.classList.add('is-active');
|
noticationContainerEL.classList.add('is-active');
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function() {
|
||||||
noticationContainerEL.classList.remove('is-active');
|
noticationContainerEL.classList.remove('is-active');
|
||||||
}, 2000)
|
}, 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.alertsService = {
|
window.alertsService = {
|
||||||
add: addNotification
|
add: addNotification
|
||||||
}
|
};
|
||||||
})();
|
})();
|
||||||
|
@ -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,
|
{
|
||||||
replaceNewTab: false
|
preserveLastCode: true,
|
||||||
}, function(items) {
|
replaceNewTab: false
|
||||||
document.forms.optionsForm.preserveLastCode.checked = items.preserveLastCode;
|
},
|
||||||
document.forms.optionsForm.replaceNewTab.checked = items.replaceNewTab;
|
function(items) {
|
||||||
});
|
document.forms.optionsForm.preserveLastCode.checked =
|
||||||
|
items.preserveLastCode;
|
||||||
|
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,
|
{
|
||||||
replaceNewTab: replaceNewTab
|
preserveLastCode: preserveLastCode,
|
||||||
}, function() {
|
replaceNewTab: replaceNewTab
|
||||||
var status = document.getElementById('js-status');
|
},
|
||||||
status.textContent = 'Settings saved.';
|
function() {
|
||||||
setTimeout(function() {
|
var status = document.getElementById('js-status');
|
||||||
status.innerHTML = ' ';
|
status.textContent = 'Settings saved.';
|
||||||
}, 750);
|
setTimeout(function() {
|
||||||
});
|
status.innerHTML = ' ';
|
||||||
|
}, 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);
|
|
||||||
|
1250
src/script.js
1250
src/script.js
File diff suppressed because it is too large
Load Diff
@ -1,9 +1,7 @@
|
|||||||
// 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;
|
||||||
var wrap = document.createElement('div');
|
var wrap = document.createElement('div');
|
||||||
@ -28,12 +26,12 @@
|
|||||||
document.body.appendChild(this.list);
|
document.body.appendChild(this.list);
|
||||||
this.list.style.position = 'fixed';
|
this.list.style.position = 'fixed';
|
||||||
});
|
});
|
||||||
},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;
|
||||||
|
})();
|
||||||
})();
|
|
||||||
|
118
src/utils.js
118
src/utils.js
@ -1,9 +1,10 @@
|
|||||||
(function () {
|
(function() {
|
||||||
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
|
||||||
@ -13,7 +14,7 @@
|
|||||||
* @param Selector that should match for next siblings
|
* @param Selector that should match for next siblings
|
||||||
* @return element Next element that mathes `selector`
|
* @return element Next element that mathes `selector`
|
||||||
*/
|
*/
|
||||||
Node.prototype.nextUntil = function (selector) {
|
Node.prototype.nextUntil = function(selector) {
|
||||||
const siblings = [...this.parentNode.querySelectorAll(selector)];
|
const siblings = [...this.parentNode.querySelectorAll(selector)];
|
||||||
const index = siblings.indexOf(this);
|
const index = siblings.indexOf(this);
|
||||||
return siblings[index + 1];
|
return siblings[index + 1];
|
||||||
@ -23,7 +24,7 @@
|
|||||||
* @param Selector that should match for next siblings
|
* @param Selector that should match for next siblings
|
||||||
* @return element Next element that mathes `selector`
|
* @return element Next element that mathes `selector`
|
||||||
*/
|
*/
|
||||||
Node.prototype.previousUntil = function (selector) {
|
Node.prototype.previousUntil = function(selector) {
|
||||||
const siblings = [...this.parentNode.querySelectorAll(selector)];
|
const siblings = [...this.parentNode.querySelectorAll(selector)];
|
||||||
const index = siblings.indexOf(this);
|
const index = siblings.indexOf(this);
|
||||||
return siblings[index - 1];
|
return siblings[index - 1];
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
@ -47,7 +56,7 @@
|
|||||||
function generateRandomId(len) {
|
function generateRandomId(len) {
|
||||||
var length = len || 10;
|
var length = len || 10;
|
||||||
var id = '';
|
var id = '';
|
||||||
for (var i = length; i--;) {
|
for (var i = length; i--; ) {
|
||||||
id += alphaNum[~~(Math.random() * alphaNum.length)];
|
id += alphaNum[~~(Math.random() * alphaNum.length)];
|
||||||
}
|
}
|
||||||
return id;
|
return id;
|
||||||
@ -75,43 +84,53 @@
|
|||||||
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':
|
||||||
case 'ForInStatement':
|
case 'ForInStatement':
|
||||||
case 'ForOfStatement':
|
case 'ForOfStatement':
|
||||||
case 'WhileStatement':
|
case 'WhileStatement':
|
||||||
var start = 1 + node.body.range[0];
|
var start = 1 + node.body.range[0];
|
||||||
var end = node.body.range[1];
|
var end = node.body.range[1];
|
||||||
var prolog = checkStr.replace('%d', varPrefix + loopId);
|
var prolog = checkStr.replace('%d', varPrefix + loopId);
|
||||||
var epilog = '';
|
var epilog = '';
|
||||||
|
|
||||||
if (node.body.type !== 'BlockStatement') {
|
if (node.body.type !== 'BlockStatement') {
|
||||||
// `while(1) doThat()` becomes `while(1) {doThat()}`
|
// `while(1) doThat()` becomes `while(1) {doThat()}`
|
||||||
prolog = '{' + prolog;
|
prolog = '{' + prolog;
|
||||||
epilog = '}';
|
epilog = '}';
|
||||||
--start;
|
--start;
|
||||||
}
|
}
|
||||||
|
|
||||||
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({
|
||||||
++loopId;
|
pos: node.range[0],
|
||||||
break;
|
str: varStr.replace('%d', varPrefix + loopId)
|
||||||
|
});
|
||||||
|
++loopId;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/* eslint-disable no-param-reassign */
|
/* eslint-disable no-param-reassign */
|
||||||
patches.sort(function (a, b) { return b.pos - a.pos }).forEach(function (patch) {
|
patches
|
||||||
code = code.slice(0, patch.pos) + patch.str + code.slice(patch.pos);
|
.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 */
|
/* eslint-disable no-param-reassign */
|
||||||
return code;
|
return code;
|
||||||
@ -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 = {
|
||||||
|
Reference in New Issue
Block a user