Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Commit

Permalink
[Update] Use window.onload with document_end instead of chrome.tabs.o…
Browse files Browse the repository at this point in the history
…nUpdated
  • Loading branch information
mkobayashime committed Jun 3, 2020
1 parent c8405d4 commit 85468b4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 30 deletions.
1 change: 0 additions & 1 deletion config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const PATHS = require('./paths');
// Merge webpack configuration files
const config = merge(common, {
entry: {
background: PATHS.src + '/background.js',
contentScript: PATHS.src + '/contentScript.js',
},
});
Expand Down
10 changes: 1 addition & 9 deletions public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,12 @@
"16": "icons/icon_16.png",
"128": "icons/icon_128.png"
},
"background": {
"scripts": [
"background.js"
],
"persistent": false
},
"permissions": [
"tabs"
],
"content_scripts": [
{
"matches": [
"https://tweetdeck.twitter.com/"
],
"run_at": "document_end",
"js": [
"contentScript.js"
]
Expand Down
11 changes: 0 additions & 11 deletions src/background.js

This file was deleted.

16 changes: 7 additions & 9 deletions src/contentScript.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"use strict"

chrome.runtime.onMessage.addListener((message) => {
if (message.type === "updated") {
getDom()
}
})
window.onload = () => {
getDom()
}

const getDom = () => {
const promise = new Promise((resolve) => {
Expand All @@ -17,7 +15,7 @@ const getDom = () => {
}
}, 250)
})

promise.then((dom) => {
setShortcuts(dom.showBtn, dom.application)
})
Expand All @@ -29,7 +27,7 @@ const setShortcuts = (showBtn, application) => {
const isOpen = () => {
return application.classList.contains('hide-detail-view-inline')
}

const clickAccount = (e) => {
if (!isOpen()) {
showBtn.click()
Expand All @@ -45,14 +43,14 @@ const setShortcuts = (showBtn, application) => {
// HTML tags to be detected as typing
const inputTags = ["INPUT", "TEXTAREA", "SELECT"]

if(inputTags.indexOf(tagName) !== -1) {
if (inputTags.indexOf(tagName) !== -1) {
return true
}
}

document.onkeyup = e => {
if (!isTyping()) {
switch(e.shiftKey && e.which) {
switch (e.shiftKey && e.which) {
case 49:
clickAccount(0)
break
Expand Down

0 comments on commit 85468b4

Please sign in to comment.