-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from drafear/develop
Warn on submission, Clar notification
- Loading branch information
Showing
12 changed files
with
124 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
function createNotification({data, href}) { | ||
let notificationId; | ||
chrome.notifications.create(data, id => { | ||
notificationId = id; | ||
}); | ||
if (href) { | ||
const clickHandler = id => { | ||
if (id !== notificationId) { | ||
return; | ||
} | ||
chrome.tabs.create({url: href}); | ||
}; | ||
const closeHandler = () => { | ||
chrome.notifications.onClicked.removeListener(clickHandler); | ||
chrome.notifications.onClosed.removeListener(closeHandler); | ||
}; | ||
chrome.notifications.onClicked.addListener(clickHandler); | ||
chrome.notifications.onClosed.addListener(closeHandler); | ||
} | ||
} | ||
|
||
chrome.runtime.onMessage.addListener(({type, data}) => { | ||
if (type === 'create-notification') { | ||
createNotification(data); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
CommonLib.runIfEnableAndLoad('notify-clarification', async () => { | ||
const contest = Betalib.getCurrentContest(); | ||
function getNotifyCount() { | ||
return $('#clar-badge').text(); | ||
} | ||
let prev = getNotifyCount(); | ||
while (true) { | ||
const cur = getNotifyCount(); | ||
if (prev !== cur) { | ||
CommonLib.createNotification({ | ||
data: { | ||
type: 'basic', | ||
iconUrl: chrome.extension.getURL('image/question.png'), | ||
title: 'Atcoder', | ||
message: 'New Clarification', | ||
}, | ||
href: `https://beta.atcoder.jp/contests/${contest.id}/clarifications`, | ||
}); | ||
prev = cur; | ||
} | ||
await CommonLib.sleep(1000); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
CommonLib.runIfEnableAndLoad('submission-warning', async () => { | ||
let cnt = 5; | ||
const event = new Event('watch.count.update'); | ||
$(document).on('mouseup touchend keyup', () => { | ||
cnt = 5; | ||
document.dispatchEvent(event); | ||
}); | ||
function waitForSelect() { | ||
return new Promise(resolve => { | ||
document.addEventListener(event.type, resolve, {once: true}); | ||
}); | ||
} | ||
while (true) { | ||
const $selects = $('#select-lang select:visible'); | ||
for (const select of $selects) { | ||
const $select = $(select); | ||
const $span = $select.next().find('.select2-selection'); | ||
const langId = $select.val(); | ||
const isWarning = await CommonLib.isEnable(`warn-${langId}`); | ||
if (langId === $select.val()) { | ||
if (isWarning) { | ||
$span.css('background-color', 'hsl(40, 90%, 85%)'); | ||
} else { | ||
$span.css('background-color', ''); | ||
} | ||
} | ||
} | ||
--cnt; | ||
if (cnt === 0) { | ||
await waitForSelect(); | ||
} | ||
await CommonLib.sleep(100); | ||
} | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters