mirror of
https://github.com/LalleSX/4chan-XZ.git
synced 2026-03-20 01:37:47 +01:00
Converted files to Typescript and added make func
This commit is contained in:
parent
6bfa8a8516
commit
67c9707175
3
Makefile
3
Makefile
@ -3,3 +3,6 @@ clean:
|
|||||||
|
|
||||||
install:
|
install:
|
||||||
npm run build
|
npm run build
|
||||||
|
|
||||||
|
sneed: clean install
|
||||||
|
cat dist/4chan-XT.user.js | xclip -selection clipboard
|
||||||
|
|||||||
47
src/Menu/CopyTextLink.ts
Normal file
47
src/Menu/CopyTextLink.ts
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import { g, Conf, d } from '../globals/globals'
|
||||||
|
import $ from '../platform/$'
|
||||||
|
import Menu from './Menu'
|
||||||
|
import type Post from '../classes/Post'
|
||||||
|
|
||||||
|
var CopyTextLink = {
|
||||||
|
text: '',
|
||||||
|
init(): void {
|
||||||
|
if (
|
||||||
|
!['index', 'thread'].includes(g.VIEW) ||
|
||||||
|
!Conf['Menu'] ||
|
||||||
|
!Conf['Copy Text Link']
|
||||||
|
) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const a: HTMLAnchorElement = $.el('a', {
|
||||||
|
className: 'copy-text-link',
|
||||||
|
href: 'javascript:;',
|
||||||
|
textContent: 'Copy Text',
|
||||||
|
})
|
||||||
|
$.on(a, 'click', CopyTextLink.copy)
|
||||||
|
|
||||||
|
return Menu.menu.addEntry({
|
||||||
|
el: a,
|
||||||
|
order: 12,
|
||||||
|
open(post: Post): boolean {
|
||||||
|
CopyTextLink.text = (post.origin || post).commentOrig()
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
copy() {
|
||||||
|
const el: HTMLTextAreaElement = $.el('textarea', {
|
||||||
|
className: 'copy-text-element',
|
||||||
|
value: CopyTextLink.text,
|
||||||
|
})
|
||||||
|
$.add(d.body, el)
|
||||||
|
el.select()
|
||||||
|
try {
|
||||||
|
d.execCommand('copy')
|
||||||
|
} catch (error) {}
|
||||||
|
return $.rm(el)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
export default CopyTextLink
|
||||||
@ -3,13 +3,8 @@ import ImageCommon from '../Images/ImageCommon'
|
|||||||
import $ from '../platform/$'
|
import $ from '../platform/$'
|
||||||
import Menu from './Menu'
|
import Menu from './Menu'
|
||||||
|
|
||||||
/*
|
|
||||||
* decaffeinate suggestions:
|
|
||||||
* DS102: Remove unnecessary code created because of implicit returns
|
|
||||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
|
|
||||||
*/
|
|
||||||
const DownloadLink = {
|
const DownloadLink = {
|
||||||
init() {
|
init(): void {
|
||||||
if (
|
if (
|
||||||
!['index', 'thread'].includes(g.VIEW) ||
|
!['index', 'thread'].includes(g.VIEW) ||
|
||||||
!Conf['Menu'] ||
|
!Conf['Menu'] ||
|
||||||
@ -18,7 +13,7 @@ const DownloadLink = {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const a = $.el('a', {
|
const a: HTMLAnchorElement = $.el('a', {
|
||||||
className: 'download-link',
|
className: 'download-link',
|
||||||
textContent: 'Download file',
|
textContent: 'Download file',
|
||||||
})
|
})
|
||||||
@ -29,7 +24,7 @@ const DownloadLink = {
|
|||||||
return Menu.menu.addEntry({
|
return Menu.menu.addEntry({
|
||||||
el: a,
|
el: a,
|
||||||
order: 100,
|
order: 100,
|
||||||
open({ file }) {
|
open({file}) {
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
71
src/Menu/Menu.ts
Normal file
71
src/Menu/Menu.ts
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
import Callbacks from '../classes/Callbacks';
|
||||||
|
import UI from '../General/UI';
|
||||||
|
import { g, Conf } from '../globals/globals';
|
||||||
|
import $ from '../platform/$';
|
||||||
|
|
||||||
|
interface Post {
|
||||||
|
isClone?: boolean;
|
||||||
|
nodes: {
|
||||||
|
info: HTMLElement;
|
||||||
|
icons: HTMLElement;
|
||||||
|
};
|
||||||
|
thread?: {
|
||||||
|
OP: Post;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const Menu = {
|
||||||
|
button: document.createElement('a'),
|
||||||
|
menu: new UI.Menu('post'),
|
||||||
|
|
||||||
|
init(): void | ReturnType<typeof Callbacks.CatalogThread.push> {
|
||||||
|
if (!['index', 'thread'].includes(g.VIEW) || !Conf['Menu']) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.button = $.el('a', {
|
||||||
|
className: 'menu-button',
|
||||||
|
href: 'javascript:;',
|
||||||
|
});
|
||||||
|
|
||||||
|
$.extend(this.button, { innerHTML: '<i class="fa fa-angle-down"></i>' });
|
||||||
|
|
||||||
|
this.menu = new UI.Menu('post');
|
||||||
|
Callbacks.Post.push({
|
||||||
|
name: 'Menu',
|
||||||
|
cb: this.node,
|
||||||
|
});
|
||||||
|
|
||||||
|
return Callbacks.CatalogThread.push({
|
||||||
|
name: 'Menu',
|
||||||
|
cb: this.catalogNode,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
node(this: Post): void | HTMLElement {
|
||||||
|
if (this.isClone) {
|
||||||
|
const button = $('.menu-button', this.nodes.info);
|
||||||
|
$.rmClass(button, 'active');
|
||||||
|
$.rm($('.dialog', this.nodes.info));
|
||||||
|
Menu.makeButton(this, button);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return $.add(this.nodes.info, Menu.makeButton(this));
|
||||||
|
},
|
||||||
|
|
||||||
|
catalogNode(this: Post): void {
|
||||||
|
return $.after(this.nodes.icons, Menu.makeButton(this.thread!.OP));
|
||||||
|
},
|
||||||
|
|
||||||
|
makeButton(post: Post, button?: HTMLElement): HTMLElement {
|
||||||
|
if (!button) {
|
||||||
|
button = Menu.button.cloneNode(true) as HTMLElement;
|
||||||
|
}
|
||||||
|
$.on(button, 'click', function (this: HTMLElement, e: Event) {
|
||||||
|
return Menu.menu.toggle(e, this, post);
|
||||||
|
});
|
||||||
|
return button;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Menu;
|
||||||
@ -2,11 +2,6 @@ import { g, Conf, d } from '../globals/globals'
|
|||||||
import $ from '../platform/$'
|
import $ from '../platform/$'
|
||||||
import Menu from './Menu'
|
import Menu from './Menu'
|
||||||
|
|
||||||
/*
|
|
||||||
* decaffeinate suggestions:
|
|
||||||
* DS102: Remove unnecessary code created because of implicit returns
|
|
||||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
|
|
||||||
*/
|
|
||||||
var ReportLink = {
|
var ReportLink = {
|
||||||
init() {
|
init() {
|
||||||
if (
|
if (
|
||||||
|
|||||||
@ -4,11 +4,6 @@ import $ from '../platform/$'
|
|||||||
import { dict } from '../platform/helpers'
|
import { dict } from '../platform/helpers'
|
||||||
import SW from './SW'
|
import SW from './SW'
|
||||||
|
|
||||||
/*
|
|
||||||
* decaffeinate suggestions:
|
|
||||||
* DS102: Remove unnecessary code created because of implicit returns
|
|
||||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
|
|
||||||
*/
|
|
||||||
var Site = {
|
var Site = {
|
||||||
defaultProperties: {
|
defaultProperties: {
|
||||||
'4chan.org': { software: 'yotsuba' },
|
'4chan.org': { software: 'yotsuba' },
|
||||||
@ -19,7 +14,7 @@ var Site = {
|
|||||||
'smug.nepu.moe': { canonical: 'smuglo.li' },
|
'smug.nepu.moe': { canonical: 'smuglo.li' },
|
||||||
},
|
},
|
||||||
|
|
||||||
init(cb) {
|
init(cb: () => void): void {
|
||||||
$.extend(Conf['siteProperties'], Site.defaultProperties)
|
$.extend(Conf['siteProperties'], Site.defaultProperties)
|
||||||
let hostname = Site.resolve()
|
let hostname = Site.resolve()
|
||||||
if (hostname && $.hasOwn(SW, Conf['siteProperties'][hostname].software)) {
|
if (hostname && $.hasOwn(SW, Conf['siteProperties'][hostname].software)) {
|
||||||
@ -28,7 +23,7 @@ var Site = {
|
|||||||
}
|
}
|
||||||
return $.onExists(doc, 'body', () => {
|
return $.onExists(doc, 'body', () => {
|
||||||
for (var software in SW) {
|
for (var software in SW) {
|
||||||
var changes
|
var changes = null
|
||||||
if ((changes = SW[software].detect?.())) {
|
if ((changes = SW[software].detect?.())) {
|
||||||
changes.software = software
|
changes.software = software
|
||||||
hostname = location.hostname.replace(/^www\./, '')
|
hostname = location.hostname.replace(/^www\./, '')
|
||||||
@ -55,13 +50,13 @@ var Site = {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
resolve(url = location) {
|
resolve(url = location.href): string {
|
||||||
let { hostname } = url
|
let { hostname: hostname } = new URL(url)
|
||||||
while (hostname && !$.hasOwn(Conf['siteProperties'], hostname)) {
|
while (hostname && !$.hasOwn(Conf['siteProperties'], hostname)) {
|
||||||
hostname = hostname.replace(/^[^.]*\.?/, '')
|
hostname = hostname.replace(/^[^.]*\.?/, '')
|
||||||
}
|
}
|
||||||
if (hostname) {
|
if (hostname) {
|
||||||
let canonical
|
let canonical: string
|
||||||
if ((canonical = Conf['siteProperties'][hostname].canonical)) {
|
if ((canonical = Conf['siteProperties'][hostname].canonical)) {
|
||||||
hostname = canonical
|
hostname = canonical
|
||||||
}
|
}
|
||||||
@ -69,14 +64,13 @@ var Site = {
|
|||||||
return hostname
|
return hostname
|
||||||
},
|
},
|
||||||
|
|
||||||
parseURL(url) {
|
parseURL(url: any): any {
|
||||||
const siteID = Site.resolve(url)
|
const siteID = Site.resolve(url)
|
||||||
return Main.parseURL(g.sites[siteID], url)
|
return Main.parseURL(g.sites[siteID], url)
|
||||||
},
|
},
|
||||||
|
set(hostname: string) {
|
||||||
set(hostname) {
|
|
||||||
for (var ID in Conf['siteProperties']) {
|
for (var ID in Conf['siteProperties']) {
|
||||||
var site
|
var site: HTMLElement
|
||||||
var properties = Conf['siteProperties'][ID]
|
var properties = Conf['siteProperties'][ID]
|
||||||
if (properties.canonical) {
|
if (properties.canonical) {
|
||||||
continue
|
continue
|
||||||
Loading…
x
Reference in New Issue
Block a user