Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor (turbolinks) {
const tq = this
tq.replaceTimer = 0
tq.appendTimer = 0
tq.turbolinks = turbolinks || Turbolinks || false
if (!tq.turbolinks || !tq.turbolinks.supported) {
console.error('No passed or global Turbolinks instance detected. TurboQuery requires Turbolinks.')
return
}
// These are timer callbacks. Bind them to the TurboQuery instance.
tq.replaceHistory = tq._replaceHistory.bind(tq)
tq.appendHistory = tq._appendHistory.bind(tq)
tq.url = Url(window.location.href, true)
}
if (assetUrlOverride) {
const uri = path.join(assetUrlOverride, hash);
return { uri: resolveUri(uri), hash };
}
const fileScale = scale === 1 ? '' : `@${scale}x`;
const fileExtension = meta.type ? `.${encodeURIComponent(meta.type)}` : '';
const suffix = `/${encodeURIComponent(meta.name)}${fileScale}${fileExtension}?platform=${encodeURIComponent(Platform.OS)}&hash=${encodeURIComponent(meta.hash)}`;
// For assets with a specified absolute URL, we use the existing origin instead of prepending the
// development server or production CDN URL origin
if (/^https?:\/\//.test(meta.httpServerLocation)) {
const uri = meta.httpServerLocation + suffix;
return { uri, hash };
}
// For assets during development, we use the development server's URL origin
if (Constants.manifest && Constants.manifest.developer) {
const baseUrl = new URL(Constants.manifest.bundleUrl);
baseUrl.set('pathname', meta.httpServerLocation + suffix);
return { uri: baseUrl.href, hash };
}
// Production CDN URIs are based on each asset file hash
return {
uri: `https://d1wp6m56sqw74a.cloudfront.net/~assets/${encodeURIComponent(hash)}`,
hash,
};
}
/**
chrome.webRequest.onBeforeSendHeaders.addListener(details => {
const {tabId, initiator, requestHeaders} = details;
const fromHelper = !_.isEmpty(_.find(requestHeaders, ({name, value}) => name === 'From' && value === 'bilibili-helper'));
if (/^chrome-extension:\/\//.test(initiator) || fromHelper) {
return;
}
const url = new Url(details.url, '', true);
const {query} = url;
if (query && query.requestFrom) return;
const tabData = this.messageStore.createData(tabId);
fetchFromHelper(url.href)
.then(res => res.json())
.then((res) => {
tabData.queue.push({
command: 'showDisabledVideoURLRequest',
data: res,
});
this.messageStore.dealWith(tabId); // 处理queue
});
}, requestFilter, ['requestHeaders']);
};
export function sanitizeURL(url: ?string): ?string {
if (url == null) {
return url;
}
const proto = URL(url).protocol;
// allow http, https, ftp
// IMPORTANT: Don't allow data: protocol because of:
// <a>here</a>
if (proto === 'https:' || proto === 'http:' || proto === 'ftp:') {
return url;
}
return undefined;
}
import * as _URLParser from 'url-parse';
const URLParser = typeof _URLParser === 'function' ? _URLParser : _URLParser.default;
export const LCHTypeURLCallback = function(inputData) {
if (typeof inputData !== 'string') {
// throw new Error('LCHErrorInputInvalid');
return false
}
if (!(new URLParser(inputData)).hostname) {
return false;
}
return true;
};
export const LCHTypeStringCanonicalExampleCallback = function() {
return 'http://example.com';
import * as _URLParser from 'url-parse';
const URLParser = typeof _URLParser === 'function' ? _URLParser : _URLParser.default;
export const LCHPrimitiveURLCallback = function(inputData) {
if (typeof inputData !== 'string') {
// throw new Error('LCHErrorInputInvalid');
return false;
}
if (!(new URLParser(inputData, {})).hostname) { // To parse an input independently of the browser's current URL (e.g. for functionality parity with the library in a Node environment), pass an empty location object as the second parameter
return false;
}
return true;
};
export const LCHPrimitiveStringCanonicalExampleCallback = function() {
return 'http://example.com';
.map(item => {
const url = parse(item.part);
const parts = parse(url.hash.replace('#', '?'), true);
const [x, y, width, height] = parts.query.xywh.split(',').map(Number);
url.set('hash', null);
const src = url.toString();
return {
start: Math.trunc(item.start / 1000),
src,
x,
y,
width,
height,
};
})
.sort((a, b) => b.start - a.start);
setPageSize () {
const url = Url(window.location.href)
const q = Url.qs.parse(url.query)
delete q.offset
delete q.height
q[this.pagesizeTarget.dataset.offsetkey] = this.pagesizeTarget.dataset.offset
q.rows = this.pagesizeTarget.selectedOptions[0].value
if (this.hasVotestatusTarget) {
q.byvotestatus = this.votestatusTarget.selectedOptions[0].value
}
url.set('query', q)
Turbolinks.visit(url.toString())
}
getUrlObject () {
const { asPath } = this.props.router
return new Url(asPath, true)
}
getUrlObject () {
const { asPath } = this.props.router
return new Url(asPath, true)
}