-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
browser-extension/chrome-extension-test/tests/copy_button_on_tasks_print.spec.ts
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,43 @@ | ||
import {test, expect} from '../fixtures'; | ||
import {Page, Locator} from "@playwright/test"; | ||
|
||
require('dotenv').config({path: './.env'}); | ||
|
||
test.describe.configure({mode: 'serial'}); | ||
|
||
let page: Page; | ||
|
||
test.beforeAll(async ({context}) => { | ||
page = await context.newPage(); | ||
await page.goto('https://atcoder.jp/contests/abc386/tasks_print'); | ||
}); | ||
|
||
test.afterAll(async () => { | ||
await page.close(); | ||
}); | ||
|
||
test('Check copy buttons are added', async () => { | ||
const copyButtons = page.locator('span.btn-copy'); | ||
await expect(copyButtons).toHaveCount(52); | ||
}); | ||
|
||
test('Check clipboard after copying', async () => { | ||
const copyButtons = page.locator('span.btn-copy'); | ||
// First button | ||
await copyButtons.nth(0).click(); | ||
let copiedText = await page.evaluate(() => navigator.clipboard.readText()); | ||
expect(copiedText.replace(/\r\n/g, '')).toBe('7 7 7 1'); | ||
|
||
// 28th button | ||
await copyButtons.nth(28).click(); | ||
copiedText = await page.evaluate(() => navigator.clipboard.readText()); | ||
expect(copiedText.replace(/\r/g, '')).toBe('4 3\n' + | ||
'4 1 B\n' + | ||
'3 2 W\n' + | ||
'1 3 B\n'); | ||
|
||
// Last button | ||
await copyButtons.nth(51).click(); | ||
copiedText = await page.evaluate(() => navigator.clipboard.readText()); | ||
expect(copiedText.replace(/\r\n/g, '')).toBe('707081320'); | ||
}); |
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
37 changes: 37 additions & 0 deletions
37
browser-extension/chrome-extension/scripts/tasks_print/main.js
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,37 @@ | ||
const isVisible = (element) => { | ||
return element.offsetWidth > 0 && | ||
element.offsetHeight > 0 && | ||
window.getComputedStyle(element).visibility !== 'hidden' | ||
&& window.getComputedStyle(element).display !== 'none'; | ||
} | ||
|
||
let index = 0; | ||
while (true) { | ||
const taskStatement = document.getElementById('task-statement'); | ||
if (taskStatement) { | ||
taskStatement.id = `task-statement-${index}`; | ||
index++; | ||
} else break; | ||
} | ||
|
||
for (let i = 0; i < index; i++) { | ||
const taskStatement = document.getElementById(`task-statement-${i}`); | ||
const divsAfterIODiv = taskStatement.querySelectorAll('div.io-style ~ div.part'); | ||
const ioDivs = Array.from(divsAfterIODiv).filter(isVisible); | ||
|
||
for (const div of ioDivs) { | ||
const button = (new DOMParser()).parseFromString(`<span class="btn btn-default btn-sm btn-copy ml-1" tabindex="0">Copy</span>`, "text/html").body.firstChild; | ||
var h3Element = div.querySelector('h3'); | ||
h3Element.insertAdjacentElement('beforeend', button); | ||
const pre = h3Element.nextElementSibling; | ||
button.addEventListener('click', function () { | ||
copyToClipboard(pre.textContent).then(() => { | ||
button.textContent = 'Copied'; | ||
setTimeout(() => { | ||
button.textContent = 'Copy'; | ||
button.blur(); | ||
}, 500); | ||
}); | ||
}); | ||
} | ||
} |
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