update USO-archive urls
This commit is contained in:
parent
91324a4a48
commit
caf0bd78cb
|
@ -277,7 +277,7 @@ const updateMan = (() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDateFromVer(style) {
|
function getDateFromVer(style) {
|
||||||
const m = style.updateUrl.startsWith(URLS.usoArchiveRaw) &&
|
const m = URLS.extractUsoArchiveId(style.updateUrl) &&
|
||||||
style.usercssData.version.match(RX_DATE2VER);
|
style.usercssData.version.match(RX_DATE2VER);
|
||||||
if (m) {
|
if (m) {
|
||||||
m[2]--; // month is 0-based in `Date` constructor
|
m[2]--; // month is 0-based in `Date` constructor
|
||||||
|
|
|
@ -35,10 +35,9 @@ bgReady.all.then(() => {
|
||||||
|
|
||||||
chrome.webRequest.onBeforeSendHeaders.addListener(maybeInstallFromDistro, {
|
chrome.webRequest.onBeforeSendHeaders.addListener(maybeInstallFromDistro, {
|
||||||
urls: [
|
urls: [
|
||||||
URLS.usoArchiveRaw + 'usercss/*.user.css',
|
|
||||||
URLS.usw + 'api/style/*.user.css',
|
URLS.usw + 'api/style/*.user.css',
|
||||||
'*://greasyfork.org/scripts/*/code/*.user.css',
|
...URLS.usoArchiveRaw.map(s => s + 'usercss/*.user.css'),
|
||||||
'*://sleazyfork.org/scripts/*/code/*.user.css',
|
...['greasy', 'sleazy'].map(s => `*://${s}fork.org/scripts/*/code/*.user.css`),
|
||||||
...[].concat(
|
...[].concat(
|
||||||
...Object.entries(maybeDistro)
|
...Object.entries(maybeDistro)
|
||||||
.map(([host, {glob}]) => makeUsercssGlobs(host, glob))),
|
.map(([host, {glob}]) => makeUsercssGlobs(host, glob))),
|
||||||
|
|
|
@ -77,20 +77,23 @@ const URLS = {
|
||||||
uso: 'https://userstyles.org/',
|
uso: 'https://userstyles.org/',
|
||||||
usoJson: 'https://userstyles.org/styles/chrome/',
|
usoJson: 'https://userstyles.org/styles/chrome/',
|
||||||
|
|
||||||
usoArchive: 'https://33kk.github.io/uso-archive/',
|
usoArchive: 'https://uso.kkx.one/',
|
||||||
usoArchiveRaw: 'https://raw.githubusercontent.com/33kk/uso-archive/flomaster/data/',
|
usoArchiveRaw: [
|
||||||
|
'https://cdn.jsdelivr.net/gh/33kk/uso-archive@flomaster/data/',
|
||||||
|
'https://raw.githubusercontent.com/33kk/uso-archive/flomaster/data/',
|
||||||
|
],
|
||||||
|
|
||||||
usw: 'https://userstyles.world/',
|
usw: 'https://userstyles.world/',
|
||||||
|
|
||||||
extractUsoArchiveId: url =>
|
extractUsoArchiveId: url =>
|
||||||
url &&
|
url &&
|
||||||
url.startsWith(URLS.usoArchiveRaw) &&
|
URLS.usoArchiveRaw.some(u => url.startsWith(u)) &&
|
||||||
Number(url.match(/\/(\d+)\.user\.css|$/)[1]),
|
Number(url.match(/\/(\d+)\.user\.css|$/)[1]),
|
||||||
extractUsoArchiveInstallUrl: url => {
|
extractUsoArchiveInstallUrl: url => {
|
||||||
const id = URLS.extractUsoArchiveId(url);
|
const id = URLS.extractUsoArchiveId(url);
|
||||||
return id ? `${URLS.usoArchive}?style=${id}` : '';
|
return id ? `${URLS.usoArchive}/style/${id}` : '';
|
||||||
},
|
},
|
||||||
makeUsoArchiveCodeUrl: id => `${URLS.usoArchiveRaw}usercss/${id}.user.css`,
|
makeUsoArchiveCodeUrl: id => `${URLS.usoArchiveRaw[0]}usercss/${id}.user.css`,
|
||||||
|
|
||||||
extractGreasyForkInstallUrl: url =>
|
extractGreasyForkInstallUrl: url =>
|
||||||
/^(https:\/\/(?:greasy|sleazy)fork\.org\/scripts\/\d+)[^/]*\/code\/[^/]*\.user\.css$|$/.exec(url)[1],
|
/^(https:\/\/(?:greasy|sleazy)fork\.org\/scripts\/\d+)[^/]*\/code\/[^/]*\.user\.css$|$/.exec(url)[1],
|
||||||
|
|
|
@ -83,7 +83,7 @@ function createStyleElement({style, name: nameLC}) {
|
||||||
parts.homepage.href = parts.homepage.title = style.url || '';
|
parts.homepage.href = parts.homepage.title = style.url || '';
|
||||||
parts.infoVer.textContent = ud ? ud.version : '';
|
parts.infoVer.textContent = ud ? ud.version : '';
|
||||||
parts.infoVer.dataset.value = ud ? ud.version : '';
|
parts.infoVer.dataset.value = ud ? ud.version : '';
|
||||||
if (`${style.updateUrl}`.startsWith(URLS.usoArchiveRaw)) {
|
if (URLS.extractUsoArchiveId(style.updateUrl)) {
|
||||||
parts.infoVer.dataset.isDate = '';
|
parts.infoVer.dataset.isDate = '';
|
||||||
} else {
|
} else {
|
||||||
delete parts.infoVer.dataset.isDate;
|
delete parts.infoVer.dataset.isDate;
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
require(['/popup/search.css']);
|
require(['/popup/search.css']);
|
||||||
|
|
||||||
const RESULT_ID_PREFIX = 'search-result-';
|
const RESULT_ID_PREFIX = 'search-result-';
|
||||||
const INDEX_URL = URLS.usoArchiveRaw + 'search-index.json';
|
const INDEX_URL = URLS.usoArchiveRaw[0] + 'search-index.json';
|
||||||
const USW_INDEX_URL = URLS.usw + 'api/index/uso-format';
|
const USW_INDEX_URL = URLS.usw + 'api/index/uso-format';
|
||||||
const USW_ICON = $create('img', {
|
const USW_ICON = $create('img', {
|
||||||
src: `${URLS.usw}favicon.ico`,
|
src: `${URLS.usw}favicon.ico`,
|
||||||
|
@ -57,6 +57,7 @@
|
||||||
const $class = sel => (sel instanceof Node ? sel : $(sel)).classList;
|
const $class = sel => (sel instanceof Node ? sel : $(sel)).classList;
|
||||||
const show = sel => $class(sel).remove('hidden');
|
const show = sel => $class(sel).remove('hidden');
|
||||||
const hide = sel => $class(sel).add('hidden');
|
const hide = sel => $class(sel).add('hidden');
|
||||||
|
const makeUsoArchiveAuthorUrl = a => `${URLS.usoArchive}browse/styles/?search=%40${a}`;
|
||||||
|
|
||||||
Object.assign(Events, {
|
Object.assign(Events, {
|
||||||
/**
|
/**
|
||||||
|
@ -77,6 +78,22 @@
|
||||||
calcCategory();
|
calcCategory();
|
||||||
ready = start();
|
ready = start();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
usoArchive: {
|
||||||
|
async openAuthor(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
await Events.usoArchive.prefetchAuthorId.call(this);
|
||||||
|
Events.openURLandHide.call(this, event);
|
||||||
|
},
|
||||||
|
async prefetchAuthorId() {
|
||||||
|
return this._fetch || (this._fetch = new Promise(async resolve => {
|
||||||
|
const url = `${URLS.usoArchiveRaw[0]}styles/${this._id}.json`;
|
||||||
|
const json = await (await fetch(url)).json();
|
||||||
|
this.href = makeUsoArchiveAuthorUrl(json.info.author.id);
|
||||||
|
resolve();
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
|
@ -277,8 +294,7 @@
|
||||||
// title
|
// title
|
||||||
Object.assign($('.search-result-title', entry), {
|
Object.assign($('.search-result-title', entry), {
|
||||||
onclick: Events.openURLandHide,
|
onclick: Events.openURLandHide,
|
||||||
href: isUsw ? `${URLS.usw}style/${id}` :
|
href: `${isUsw ? URLS.usw : URLS.usoArchive}style/${id}`,
|
||||||
`${URLS.usoArchive}?category=${category}&style=${id}`,
|
|
||||||
});
|
});
|
||||||
if (isUsw) $('.search-result-title', entry).prepend(USW_ICON.cloneNode(true));
|
if (isUsw) $('.search-result-title', entry).prepend(USW_ICON.cloneNode(true));
|
||||||
$('.search-result-title span', entry).textContent =
|
$('.search-result-title span', entry).textContent =
|
||||||
|
@ -291,7 +307,7 @@
|
||||||
const auto = URLS.uso + `auto_style_screenshots/${id}${USO_AUTO_PIC_SUFFIX}`;
|
const auto = URLS.uso + `auto_style_screenshots/${id}${USO_AUTO_PIC_SUFFIX}`;
|
||||||
Object.assign(elShot, {
|
Object.assign(elShot, {
|
||||||
src: shotName && !shotName.endsWith(USO_AUTO_PIC_SUFFIX)
|
src: shotName && !shotName.endsWith(USO_AUTO_PIC_SUFFIX)
|
||||||
? `${shotArchived ? URLS.usoArchiveRaw : URLS.uso + 'style_'}screenshots/${shotName}`
|
? `${shotArchived ? URLS.usoArchiveRaw[0] : URLS.uso + 'style_'}screenshots/${shotName}`
|
||||||
: auto,
|
: auto,
|
||||||
_src: auto,
|
_src: auto,
|
||||||
onerror: fixScreenshot,
|
onerror: fixScreenshot,
|
||||||
|
@ -302,9 +318,14 @@
|
||||||
Object.assign($('[data-type="author"] a', entry), {
|
Object.assign($('[data-type="author"] a', entry), {
|
||||||
textContent: author,
|
textContent: author,
|
||||||
title: author,
|
title: author,
|
||||||
href: isUsw ? `${URLS.usw}user/${eAuthor}` :
|
}, isUsw ? {
|
||||||
`${URLS.usoArchive}?author=${eAuthor.replace(/%20/g, '+')}`,
|
href: `${URLS.usw}user/${eAuthor}`,
|
||||||
onclick: Events.openURLandHide,
|
onclick: Events.openURLandHide,
|
||||||
|
} : {
|
||||||
|
_id: id,
|
||||||
|
href: makeUsoArchiveAuthorUrl(eAuthor),
|
||||||
|
onclick: Events.usoArchive.openAuthor,
|
||||||
|
onmousedown: Events.usoArchive.prefetchAuthorId,
|
||||||
});
|
});
|
||||||
// rating
|
// rating
|
||||||
$('[data-type="rating"]', entry).dataset.class =
|
$('[data-type="rating"]', entry).dataset.class =
|
||||||
|
|
Loading…
Reference in New Issue
Block a user