mirror of
https://github.com/LalleSX/4chan-XZ.git
synced 2026-01-30 09:48:12 +01:00
types
This commit is contained in:
parent
87903aab6b
commit
a6678efea7
@ -1,4 +1,4 @@
|
|||||||
import { Conf, d,doc, g } from "../globals/globals"
|
import { Conf, d, doc, g } from "../globals/globals"
|
||||||
import Main from "../main/Main"
|
import Main from "../main/Main"
|
||||||
import $ from "../platform/$"
|
import $ from "../platform/$"
|
||||||
import Captcha from "./Captcha"
|
import Captcha from "./Captcha"
|
||||||
@ -8,7 +8,7 @@ const CaptchaReplace = {
|
|||||||
if ((g.SITE.software !== 'yotsuba') || (d.cookie.indexOf('pass_enabled=1') >= 0)) { return }
|
if ((g.SITE.software !== 'yotsuba') || (d.cookie.indexOf('pass_enabled=1') >= 0)) { return }
|
||||||
|
|
||||||
if (Conf['Force Noscript Captcha'] && Main.jsEnabled) {
|
if (Conf['Force Noscript Captcha'] && Main.jsEnabled) {
|
||||||
$.ready(Captcha.replace.noscript)
|
$.ready(Captcha.Replace.noscript)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,12 +25,12 @@ const CaptchaReplace = {
|
|||||||
let noscript, original, toggle
|
let noscript, original, toggle
|
||||||
if (!((original = $('#g-recaptcha')) && (noscript = $('noscript', original.parentNode)))) { return }
|
if (!((original = $('#g-recaptcha')) && (noscript = $('noscript', original.parentNode)))) { return }
|
||||||
const span = $.el('span',
|
const span = $.el('span',
|
||||||
{id: 'captcha-forced-noscript'})
|
{ id: 'captcha-forced-noscript' })
|
||||||
$.replace(noscript, span)
|
$.replace(noscript, span)
|
||||||
$.rm(original)
|
$.rm(original)
|
||||||
const insert = function() {
|
const insert = function () {
|
||||||
span.innerHTML = noscript.textContent
|
span.innerHTML = noscript.textContent
|
||||||
return Captcha.replace.iframe($('iframe[src^="https://www.google.com/recaptcha/"]', span))
|
return Captcha.Replace.iframe($('iframe[src^="https://www.google.com/recaptcha/"]', span))
|
||||||
}
|
}
|
||||||
if (toggle = $('#togglePostFormLink a, #form-link')) {
|
if (toggle = $('#togglePostFormLink a, #form-link')) {
|
||||||
return $.on(toggle, 'click', insert)
|
return $.on(toggle, 'click', insert)
|
||||||
@ -44,7 +44,7 @@ const CaptchaReplace = {
|
|||||||
if (lang = Conf['captchaLanguage'].trim()) {
|
if (lang = Conf['captchaLanguage'].trim()) {
|
||||||
const src = /[?&]hl=/.test(iframe.src) ?
|
const src = /[?&]hl=/.test(iframe.src) ?
|
||||||
iframe.src.replace(/([?&]hl=)[^&]*/, '$1' + encodeURIComponent(lang))
|
iframe.src.replace(/([?&]hl=)[^&]*/, '$1' + encodeURIComponent(lang))
|
||||||
:
|
:
|
||||||
iframe.src + `&hl=${encodeURIComponent(lang)}`
|
iframe.src + `&hl=${encodeURIComponent(lang)}`
|
||||||
if (iframe.src !== src) { iframe.src = src }
|
if (iframe.src !== src) { iframe.src = src }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -133,7 +133,7 @@ $.extend = function (object: object, properties: object) {
|
|||||||
|
|
||||||
$.hasOwn = (obj: object, key: string) => Object.prototype.hasOwnProperty.call(obj, key)
|
$.hasOwn = (obj: object, key: string) => Object.prototype.hasOwnProperty.call(obj, key)
|
||||||
|
|
||||||
$.getOwn = function (obj, key) {
|
$.getOwn = function (obj: Object, key: string): any {
|
||||||
if (Object.prototype.hasOwnProperty.call(obj, key)) { return obj[key] } else { return undefined }
|
if (Object.prototype.hasOwnProperty.call(obj, key)) { return obj[key] } else { return undefined }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,10 +148,8 @@ $.ajax = (function () {
|
|||||||
const r = (function (url: string, options = dict(), cb: Callbacks) {
|
const r = (function (url: string, options = dict(), cb: Callbacks) {
|
||||||
if (options.responseType == null) { options.responseType = 'json' }
|
if (options.responseType == null) { options.responseType = 'json' }
|
||||||
if (!options.type) { options.type = (options.form && 'post') || 'get' }
|
if (!options.type) { options.type = (options.form && 'post') || 'get' }
|
||||||
// XXX https://forums.lanik.us/viewtopic.php?f=64&t=24173&p=78310
|
|
||||||
url = url.replace(/^((?:https?:)?\/\/(?:\w+\.)?(?:4chan|4channel|4cdn)\.org)\/adv\//, '$1//adv/')
|
url = url.replace(/^((?:https?:)?\/\/(?:\w+\.)?(?:4chan|4channel|4cdn)\.org)\/adv\//, '$1//adv/')
|
||||||
if (platform === 'crx') {
|
if (platform === 'crx') {
|
||||||
// XXX https://bugs.chromium.org/p/chromium/issues/detail?id=920638
|
|
||||||
if (Conf['Work around CORB Bug'] && g.SITE.software === 'yotsuba' && !options.testCORB && FormData.prototype.entries) {
|
if (Conf['Work around CORB Bug'] && g.SITE.software === 'yotsuba' && !options.testCORB && FormData.prototype.entries) {
|
||||||
return $.ajaxPage(url, options)
|
return $.ajaxPage(url, options)
|
||||||
}
|
}
|
||||||
@ -199,7 +197,7 @@ $.ajax = (function () {
|
|||||||
$.global(function () {
|
$.global(function () {
|
||||||
window.FCX.requests = Object.create(null)
|
window.FCX.requests = Object.create(null)
|
||||||
|
|
||||||
document.addEventListener('4chanXAjax', function (e) {
|
document.addEventListener('4chanXAjax', function (e: CustomEvent) {
|
||||||
let fd, r
|
let fd, r
|
||||||
const { url, timeout, responseType, withCredentials, type, onprogress, form, headers, id } = e.detail
|
const { url, timeout, responseType, withCredentials, type, onprogress, form, headers, id } = e.detail
|
||||||
window.FCX.requests[id] = (r = new XMLHttpRequest())
|
window.FCX.requests[id] = (r = new XMLHttpRequest())
|
||||||
@ -425,11 +423,11 @@ $.X = function (path, root) {
|
|||||||
return d.evaluate(path, root, null, 7, null)
|
return d.evaluate(path, root, null, 7, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
$.addClass = function (el, ...classNames) {
|
$.addClass = function (el: Element, ...classNames: string[]) {
|
||||||
for (const className of classNames) { el.classList.add(className) }
|
for (const className of classNames) { el.classList.add(className) }
|
||||||
}
|
}
|
||||||
|
|
||||||
$.rmClass = function (el, ...classNames) {
|
$.rmClass = function (el: Element, ...classNames: string[]) {
|
||||||
for (const className of classNames) { el.classList.remove(className) }
|
for (const className of classNames) { el.classList.remove(className) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -493,8 +491,8 @@ $.one = function (el, events, handler) {
|
|||||||
}
|
}
|
||||||
return $.on(el, events, cb)
|
return $.on(el, events, cb)
|
||||||
}
|
}
|
||||||
|
let cloneInto: (obj: object, win: Window) => object
|
||||||
$.event = function (event, detail, root = d) {
|
$.event = function (event: Event, detail: object, root = d) {
|
||||||
if (!globalThis.chrome?.extension) {
|
if (!globalThis.chrome?.extension) {
|
||||||
if ((detail != null) && (typeof cloneInto === 'function')) {
|
if ((detail != null) && (typeof cloneInto === 'function')) {
|
||||||
detail = cloneInto(detail, d.defaultView)
|
detail = cloneInto(detail, d.defaultView)
|
||||||
@ -861,7 +859,7 @@ if (platform === 'crx') {
|
|||||||
|
|
||||||
$.sync = (key: string, cb: Callbacks) => $.syncing[key] = cb
|
$.sync = (key: string, cb: Callbacks) => $.syncing[key] = cb
|
||||||
|
|
||||||
$.forceSync = function () { }
|
$.forceSync = function () {/* empty */ }
|
||||||
|
|
||||||
$.delete = function (keys: string | string[], cb: Callbacks) {
|
$.delete = function (keys: string | string[], cb: Callbacks) {
|
||||||
let key
|
let key
|
||||||
@ -931,7 +929,7 @@ if (platform === 'crx') {
|
|||||||
return result
|
return result
|
||||||
})()
|
})()
|
||||||
} else {
|
} else {
|
||||||
$.getValue = function () { }
|
$.getValue = function () {/* empty */ }
|
||||||
$.listValues = () => []
|
$.listValues = () => []
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -973,7 +971,7 @@ if (platform === 'crx') {
|
|||||||
return cb(newValue, key)
|
return cb(newValue, key)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
$.forceSync = function () { }
|
$.forceSync = function () {/* empty */ }
|
||||||
} else if ((typeof GM_deleteValue !== 'undefined' && GM_deleteValue !== null) || $.hasStorage) {
|
} else if ((typeof GM_deleteValue !== 'undefined' && GM_deleteValue !== null) || $.hasStorage) {
|
||||||
$.sync = function (key, cb) {
|
$.sync = function (key, cb) {
|
||||||
key = g.NAMESPACE + key
|
key = g.NAMESPACE + key
|
||||||
@ -1015,7 +1013,7 @@ if (platform === 'crx') {
|
|||||||
keys = [keys]
|
keys = [keys]
|
||||||
}
|
}
|
||||||
for (const key of keys) {
|
for (const key of keys) {
|
||||||
$.deleteValue(g.NAMESPACE + key)
|
$.deleteValue(g.NAMESPACE + key, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1024,7 +1022,7 @@ if (platform === 'crx') {
|
|||||||
$.getSync = function (items, cb) {
|
$.getSync = function (items, cb) {
|
||||||
for (const key in items) {
|
for (const key in items) {
|
||||||
let val2
|
let val2
|
||||||
if (val2 = $.getValue(g.NAMESPACE + key)) {
|
if (val2 = $.getValue(g.NAMESPACE + key, null)) {
|
||||||
try {
|
try {
|
||||||
items[key] = dict.json(val2)
|
items[key] = dict.json(val2)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -1056,7 +1054,7 @@ if (platform === 'crx') {
|
|||||||
$.delete(['previousversion', 'QR Size', 'QR.persona'], cb)
|
$.delete(['previousversion', 'QR Size', 'QR.persona'], cb)
|
||||||
try {
|
try {
|
||||||
$.delete($.listValues().map(key => key.replace(g.NAMESPACE, '')), cb)
|
$.delete($.listValues().map(key => key.replace(g.NAMESPACE, '')), cb)
|
||||||
} catch (error) { }
|
} catch (error) {/* empty */ }
|
||||||
return cb
|
return cb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,7 +28,7 @@ const Site = {
|
|||||||
}
|
}
|
||||||
return $.onExists(doc, 'body', () => {
|
return $.onExists(doc, 'body', () => {
|
||||||
for (const software in SW) {
|
for (const software in SW) {
|
||||||
var changes
|
let changes
|
||||||
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\./, '')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user