|
1 | | -interface Window { |
2 | | - __UPDATE_BY_SELF__: any; |
| 1 | +{ |
| 2 | + window.addEventListener('submit', () => { |
| 3 | + // サブミットされてすぐには更新されないので、1s待つ |
| 4 | + setTimeout(() => { |
| 5 | + console.log('UPDATE_BY_SELF:'); |
| 6 | + }, 1000); |
| 7 | + }, true); |
3 | 8 | } |
4 | | - |
5 | | -(function(){ |
6 | | - window.__UPDATE_BY_SELF__ = window.__UPDATE_BY_SELF__ || {}; |
7 | | - |
8 | | - const loginName = '_loginName_'; |
9 | | - let lastTime = { |
10 | | - addComment: 0, |
11 | | - updateComment: 0 |
12 | | - }; |
13 | | - |
14 | | - function checkAddComment(mutations) { |
15 | | - for (const mutation of mutations) { |
16 | | - for (const el of Array.from(mutation.addedNodes) as HTMLElement[]) { |
17 | | - if (!el || !el.querySelector) continue; |
18 | | - |
19 | | - const authorEl = el.querySelector('.author'); |
20 | | - if (!authorEl) continue; |
21 | | - |
22 | | - const author = authorEl.textContent; |
23 | | - if (author !== loginName) continue; |
24 | | - |
25 | | - const now = Date.now(); |
26 | | - if (lastTime.addComment + 300 > now) continue; |
27 | | - |
28 | | - lastTime.addComment = now; |
29 | | - console.log('UPDATE_BY_SELF:'); |
30 | | - |
31 | | - return; |
32 | | - } |
33 | | - } |
34 | | - } |
35 | | - |
36 | | - function checkUpdateComment(mutations) { |
37 | | - const el = mutations[0].target; |
38 | | - if (!el || !el.classList) return; |
39 | | - |
40 | | - if (!el.classList.contains('comment-body')) return; |
41 | | - |
42 | | - const now = Date.now(); |
43 | | - if (lastTime.updateComment + 300 > now) return; |
44 | | - |
45 | | - lastTime.updateComment = now; |
46 | | - console.log('UPDATE_COMMENT_BY_SELF:'); |
47 | | - } |
48 | | - |
49 | | - // conversation tab |
50 | | - { |
51 | | - const target = document.querySelector('.js-discussion'); |
52 | | - if (target) { |
53 | | - if (window.__UPDATE_BY_SELF__.conversation) { |
54 | | - window.__UPDATE_BY_SELF__.conversation.disconnect(); |
55 | | - } |
56 | | - |
57 | | - const observer = new MutationObserver((mutations) => { |
58 | | - checkAddComment(mutations); |
59 | | - checkUpdateComment(mutations); |
60 | | - }); |
61 | | - |
62 | | - observer.observe(target, {subtree: true, childList: true}); |
63 | | - |
64 | | - window.__UPDATE_BY_SELF__.conversation = observer; |
65 | | - } |
66 | | - } |
67 | | - |
68 | | - // files tab |
69 | | - { |
70 | | - const target = document.querySelector('#files.diff-view'); |
71 | | - if (target) { |
72 | | - if (window.__UPDATE_BY_SELF__.files) { |
73 | | - window.__UPDATE_BY_SELF__.files.disconnect(); |
74 | | - } |
75 | | - |
76 | | - const observer = new MutationObserver((mutations) => { |
77 | | - checkAddComment(mutations); |
78 | | - checkUpdateComment(mutations); |
79 | | - }); |
80 | | - |
81 | | - observer.observe(target, {subtree: true, childList: true}); |
82 | | - |
83 | | - window.__UPDATE_BY_SELF__.files = observer; |
84 | | - } |
85 | | - } |
86 | | - |
87 | | - // submit review |
88 | | - { |
89 | | - window.addEventListener('beforeunload', () =>{ |
90 | | - const submitButton = document.querySelector('#submit-review button[type="submit"]'); |
91 | | - // if it has disabled, submit review |
92 | | - if (submitButton && submitButton.hasAttribute('disabled')) { |
93 | | - console.log('UPDATE_BY_SELF:'); |
94 | | - } |
95 | | - }); |
96 | | - } |
97 | | -})(); |
0 commit comments