From 025e2997b9fa7cdc7b090ae1c4769c28ddb54678 Mon Sep 17 00:00:00 2001 From: Ruihui Yan Date: Fri, 16 Nov 2018 23:55:14 -0500 Subject: [PATCH] lint code to conform with JS Standard --- .DS_Store | Bin 0 -> 6148 bytes .../MediaProviders/baseMediaProvider.js | 50 +++--- src/ServiceProviders/MediaProviders/docs.js | 36 ++--- src/ServiceProviders/MediaProviders/vimeo.js | 2 +- .../MediaProviders/youtube.js | 36 ++--- src/main.js | 145 +++++++++--------- src/preload.js | 31 ++-- src/renderer.js | 97 ++++++------ 8 files changed, 200 insertions(+), 197 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a4ba1d8c8771bd25c7b11085c9c32b0f360d61ae GIT binary patch literal 6148 zcmeHKO-sW-5Pf5!7K+fL$NdZbgQe7i=l%gPDN?AWG-Y8!SOHj26-6gAqUKrGg$G{|MQgNub9m~y!%UHLHR;}KwCK>FAMd}y9xr$v zn{IH#iIGQYj~%lfnAPERnt4rU!@xZQ-=?mLt`nMZ(M!hcX#N&?u6)J5f`MQl7zhUb zJ_Ee7RTfLb7=wXeAQ<>!K+lInRm_fqVL3WDloo(k(_Dme?IkoPIcCSfkRFOyD$!EK zTMV&u+LOm+$HCCjA>Mq5Kl!tHk@9rbPbD0Z4Py)jf`KUml`U6#|KIbInQii?DX|I$ zf`Na=fYh7qX3dxKyY0O(sk5m= 8) { return match[3] diff --git a/src/ServiceProviders/MediaProviders/youtube.js b/src/ServiceProviders/MediaProviders/youtube.js index b4e6efe..8d538c8 100644 --- a/src/ServiceProviders/MediaProviders/youtube.js +++ b/src/ServiceProviders/MediaProviders/youtube.js @@ -1,33 +1,33 @@ -const baseMediaProvider = require("./baseMediaProvider"); +const baseMediaProvider = require('./baseMediaProvider') class youtubeProvider extends baseMediaProvider { - constructor() { - super(); - this.name = "youtube"; - this.response.type = "iframe"; - this.response.eventName = "youtube"; + constructor () { + super() + this.name = 'youtube' + this.response.type = 'iframe' + this.response.eventName = 'youtube' } - matcher(link) { - if (link != undefined || link != "") { - var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=|\?v=)([^#\&\?]*).*/; - var match = link.match(regExp); - if (match && match[2].length == 11) { - return match[2]; + matcher (link) { + if (link !== undefined || link !== '') { + var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=|\?v=)([^#\&\?]*).*/ + var match = link.match(regExp) + if (match && match[2].length === 11) { + return match[2] } } - return false; + return false } - extractContents(link) { - let match = this.matcher(link); - this.response.content = match; + extractContents (link) { + let match = this.matcher(link) + this.response.content = match // let web = 'https://www.youtube.com/embed/' + match + '?autoplay=1&enablejsapi=1' // this.response.content = `` - return true; + return true } } -module.exports = youtubeProvider; +module.exports = youtubeProvider diff --git a/src/main.js b/src/main.js index 783dc31..2623519 100644 --- a/src/main.js +++ b/src/main.js @@ -7,19 +7,20 @@ const { session, ipcMain, Notification -} = require("electron"); -const providers = require("./ServiceProviders/providers"); -const fullscreenToggle = require("./lib/fullscreen-toggle"); -const utils = require("./lib/util"); -const path = require("path"); -const ActionManager = require("./core/action-manager") + +} = require('electron') +const providers = require('./ServiceProviders/providers') +const fullscreenToggle = require('./lib/fullscreen-toggle') +const utils = require('./lib/util') +const path = require('path') +const ActionManager = require('./core/action-manager') // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. -let mainWindow; -let tray; +let mainWindow +let tray -function createWindow() { +function createWindow () { // create config let config = { width: 400, @@ -29,40 +30,40 @@ function createWindow() { plugins: true, preload: path.join(__dirname, 'preload.js') }, - titleBarStyle: "customButtonsOnHover", - }; + titleBarStyle: 'customButtonsOnHover' + } // Create the browser window. - mainWindow = new BrowserWindow(config); - mainWindow.setMenu(null); + mainWindow = new BrowserWindow(config) + mainWindow.setMenu(null) - if (process.platform == "darwin") app.dock.hide(); + if (process.platform === 'darwin') app.dock.hide() - mainWindow.setVisibleOnAllWorkspaces(true); - mainWindow.setFullScreenable(false); + mainWindow.setVisibleOnAllWorkspaces(true) + mainWindow.setFullScreenable(false) // and load the index.html of the app. - mainWindow.loadFile('src/index.html'); + mainWindow.loadFile('src/index.html') // mainWindow.loadURL('https://www.netflix.com') // Open the DevTools. - if (process.env.DEV==1) mainWindow.webContents.openDevTools(); + if (process.env.DEV === 1) mainWindow.webContents.openDevTools() // Emitted when the window is closed. - mainWindow.on("closed", function() { + mainWindow.on('closed', function () { // Dereference the window object, usually you would store windows // in an array if your app supports multi windows, this is the time // when you should delete the corresponding element. - mainWindow = null; - }); + mainWindow = null + }) // Disable new browser windows and popups - mainWindow.webContents.on("new-window", function(e, url) { - e.preventDefault(); - providers.run(mainWindow, url); - mainWindow.focus(); - }); + mainWindow.webContents.on('new-window', function (e, url) { + e.preventDefault() + providers.run(mainWindow, url) + mainWindow.focus() + }) let actionManager = new ActionManager(mainWindow) actionManager.applyActions() @@ -75,89 +76,89 @@ function createWindow() { } let createMenuTray = () => { - tray = new Tray(__dirname + "/assets/images/tray.png"); + tray = new Tray(path.join(__dirname, '/assets/images/tray.png')) const trayMenus = [ - { role: "about" }, + { role: 'about' }, { - label: "Exit Fullscreen", - click() { - fullscreenToggle(mainWindow, true); + label: 'Exit Fullscreen', + click () { + fullscreenToggle(mainWindow, true) } }, { - label: "Quit", - click() { - app.quit(); + label: 'Quit', + click () { + app.quit() } }, { - label: "Bring H2 to the front", - click() { - utils.resetWindowToFloat(mainWindow); + label: 'Bring H2 to the front', + click () { + utils.resetWindowToFloat(mainWindow) } } - ]; + ] - const contextMenu = Menu.buildFromTemplate(trayMenus); + const contextMenu = Menu.buildFromTemplate(trayMenus) - tray.setToolTip("H2"); - tray.setContextMenu(contextMenu); - tray.setTitle("H2"); - tray.on("click", function(event) { - console.log("called"); - !mainWindow.isFocused() ? mainWindow.focus() : true; - }); -}; + tray.setToolTip('H2') + tray.setContextMenu(contextMenu) + tray.setTitle('H2') + tray.on('click', function (event) { + console.log('called') + !mainWindow.isFocused() ? mainWindow.focus() : true + }) +} // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. -app.on("ready", () => { - session.defaultSession.clearStorageData(); - createWindow(); - utils.resetWindowToFloat(mainWindow); - createMenuTray(); -}); +app.on('ready', () => { + session.defaultSession.clearStorageData() + createWindow() + utils.resetWindowToFloat(mainWindow) + createMenuTray() +}) -app.on("will-quit", () => { +app.on('will-quit', () => { // Unregister all shortcuts. - globalShortcut.unregisterAll(); -}); + globalShortcut.unregisterAll() +}) // Quit when all windows are closed. -app.on("window-all-closed", function() { +app.on('window-all-closed', function () { // On OS X it is common for applications and their menu bar // to stay active until the user quits explicitly with Cmd + Q // if (process.platform !== 'darwin') { - app.quit(); + app.quit() // } -}); +}) // Unregister all shortcuts. -app.on("will-quit", () => { - globalShortcut.unregisterAll(); -}); +app.on('will-quit', () => { + globalShortcut.unregisterAll() +}) -app.on("activate", function() { +app.on('activate', function () { // On OS X it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. if (mainWindow === null) { - createWindow(); + createWindow() } -}); +}) -ipcMain.on("exit-full-screen", () => { - fullscreenToggle(mainWindow, true); -}); +ipcMain.on('exit-full-screen', () => { + fullscreenToggle(mainWindow, true) +}) -ipcMain.on("openLink", (ev, arg) => { +ipcMain.on('openLink', (ev, arg) => { console.log(arg) mainWindow.loadURL(arg) - mainWindow.webContents.on("did-finish-load", (event, url) => { + mainWindow.webContents.on('did-finish-load', (event, url) => { console.log('asking') - mainWindow.webContents.send("send-full-screen", "ping") + mainWindow.webContents.send('send-full-screen', 'ping') }) -}); +}) // In this file you can include the rest of your app's specific main process // code. You can also put them in separate files and require them here. diff --git a/src/preload.js b/src/preload.js index 4f5eeb1..994ca3f 100644 --- a/src/preload.js +++ b/src/preload.js @@ -74,26 +74,27 @@ function simulate(element, eventName) return element; } -function extend(destination, source) { - for (var property in source) - destination[property] = source[property]; - return destination; +function extend (destination, source) { + for (var property in source) { + destination[property] = source[property] + } + return destination } var eventMatchers = { - 'HTMLEvents': /^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/, - 'MouseEvents': /^(?:click|dblclick|mouse(?:down|up|over|move|out))$/ + 'HTMLEvents': /^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/, + 'MouseEvents': /^(?:click|dblclick|mouse(?:down|up|over|move|out))$/ } var defaultOptions = { - pointerX: 0, - pointerY: 0, - button: 0, - ctrlKey: false, - altKey: false, - shiftKey: false, - metaKey: false, - bubbles: true, - cancelable: true + pointerX: 0, + pointerY: 0, + button: 0, + ctrlKey: false, + altKey: false, + shiftKey: false, + metaKey: false, + bubbles: true, + cancelable: true } ipcRenderer.on('send-full-screen', (ev, arg) => { diff --git a/src/renderer.js b/src/renderer.js index 1e6f02d..d7623bf 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -2,29 +2,28 @@ // be executed in the renderer process for that window. // All of the Node.js APIs are available in this process. -let { clipboard, ipcRenderer } = require("electron"); -const notif = require("./lib/notifications"); - -let player; +let { clipboard, ipcRenderer } = require('electron') +const notif = require('./lib/notifications') +let player let apiPromise = new Promise(resolve => { window.onYouTubeIframeAPIReady = () => { // console.log("YouTube API loaded"); - resolve(); - }; - const tag = document.createElement("script"); - tag.src = "https://www.youtube.com/iframe_api"; + resolve() + } + const tag = document.createElement('script') + tag.src = 'https://www.youtube.com/iframe_api' - let firstScriptTag = document.getElementsByTagName('script')[0]; - firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); -}); + let firstScriptTag = document.getElementsByTagName('script')[0] + firstScriptTag.parentNode.insertBefore(tag, firstScriptTag) +}) -async function putYoutube(videoId) { +async function putYoutube (videoId) { await apiPromise let pl = new YT.Player('video', { - height: "100%", - width: "100%", + height: '100%', + width: '100%', videoId: videoId, playerVars: { autoplay: 1, @@ -39,7 +38,7 @@ async function putYoutube(videoId) { // console.log(event) } } - }); + }) document.body.innerHTML += ``; window.player = pl @@ -49,58 +48,60 @@ async function putYoutube(videoId) { } } -function putVimeo(videoId) { - let pl = new Vimeo.Player(document.querySelector("#video"), { +function putVimeo (videoId) { + let pl = new Vimeo.Player(document.querySelector('#video'), { id: videoId, autoplay: true, transparent: false - }); + }) player = { api: pl, status: 1 } } -function togglePlay() { +function togglePlay () { if (player) { - if(player.status == 1) { - player.pauseVideo() - player.status = 0 - } else if (player.status == 0) { - player.playVideo() - player.status = 1 + if (player.status === 1) { + player.pauseVideo() + player.status = 0 + } else if (player.status === 0) { + player.playVideo() + player.status = 1 } } else { - alert("Play a video first"); + alert('Play a video first') } } -function defaultiFrame(arg) { - let web = ``; - document.querySelector("#video").innerHTML = web; +function defaultiFrame (arg) { + let web = `` + document.querySelector('#video').innerHTML = web } -window.addEventListener('keyup', function(e){ - if(e.key == 'Escape') +window.addEventListener('keyup', function (e) { + if (e.key === 'Escape') { ipcRenderer.send('exit-full-screen') + } }) ipcRenderer.on('togglePlay', (ev, arg) => { togglePlay() }) -ipcRenderer.on("youtube", async (ev, arg) => { - await putYoutube(arg); +ipcRenderer.on('youtube', async (ev, arg) => { + await putYoutube(arg) let frame = document.getElementById('video') console.log(frame) - frame.addEventListener("load", function() { - setTimeout( () => { - if(document.getElementById('video').contentDocument.querySelector('.ytp-error-content-wrap-reason')) - ipcRenderer.send('openLink', 'https://youtube.com/watch?v='+arg) + frame.addEventListener('load', function () { + setTimeout(() => { + if (document.getElementById('video').contentDocument.querySelector('.ytp-error-content-wrap-reason')) { + ipcRenderer.send('openLink', 'https://youtube.com/watch?v=' + arg) + } }, 2000) - }); -}); + }) +}) ipcRenderer.on('vimeo', (ev, arg) => { putVimeo(arg) @@ -110,15 +111,15 @@ ipcRenderer.on('googleDocs', (ev, arg) => { defaultiFrame(arg) }) -ipcRenderer.on("invalidUrl", () => { - notif("Oops! This isn't supported URL"); -}); +ipcRenderer.on('invalidUrl', () => { + notif('Oops! This isn\'t supported URL') +}) -ipcRenderer.on("alertUser", (event, message, url) => { - var userInput = confirm(message); - if (userInput == true) { - alert( +ipcRenderer.on('alertUser', (event, message, url) => { + var userInput = confirm(message) + if (userInput === true) { + alert ( `Step 1. Copy the URL\nStep 2. Open in your favorite browser.\n\n${url}` - ); + ) } -}); +})