forked from refined-github/refined-github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-file.js
57 lines (47 loc) · 1.47 KB
/
setup-file.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import {parseHTML, NodeFilter} from 'linkedom';
const globals = [
'navigator',
'document',
'HTMLAnchorElement',
'DocumentFragment',
'Node',
];
const {window} = parseHTML('...', 'text/html');
globalThis.location = new URL('https://github.com');
for (const property of globals) {
globalThis[property] ??= window[property];
}
class Location {}
globalThis.Location = Location;
globalThis.NodeFilter = NodeFilter;
globalThis.location = new URL('https://github.com');
const link = document.createElement('link');
link.rel = 'alternate';
link.type = 'application/atom+xml';
navigateToCommits('master', '/refined-github/refined-github/commits');
document.head.append(link);
// eslint-disable-next-line import/prefer-default-export
export function navigateToCommits(branch, pathname) {
link.href = `https://github.com/refined-github/refined-github/commits/${branch}.atom`;
link.title = `Recent Commits to ava:${branch}`;
location.pathname = pathname;
}
// No native support https://github.com/WebReflection/linkedom/issues/156
window.Text.prototype.splitText = function (offset) {
const [start, end] = (() => {
if (offset <= 0) {
return ['', this.data];
}
if (offset >= this.data.length) {
return [this.data, ''];
}
return [
this.data.slice(0, Math.max(0, offset)),
this.data.slice(Math.max(0, offset)),
];
})();
const newNode = window.document.createTextNode(end);
this.parentNode.insertBefore(newNode, this.nextSibling);
this.data = start;
return newNode;
};