Skip to content

Commit

Permalink
fix #1927: update css from greasyfork
Browse files Browse the repository at this point in the history
  • Loading branch information
tophf committed Feb 17, 2025
1 parent 4d5a925 commit 86deb15
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 10 additions & 5 deletions src/background/update-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {UCD} from '@/js/consts';
import * as prefs from '@/js/prefs';
import {calcStyleDigest, styleSectionsEqual} from '@/js/sections-util';
import {chromeLocal} from '@/js/storage-util';
import {extractUsoaId, isCdnUrl, isLocalhost, usoApi} from '@/js/urls';
import {extractUsoaId, isCdnUrl, isLocalhost, rxGF, usoApi} from '@/js/urls';
import {debounce, deepMerge, getHost, sleep} from '@/js/util';
import {ignoreChromeError} from '@/js/util-webext';
import {bgBusy} from './common';
Expand Down Expand Up @@ -173,15 +173,20 @@ export async function checkStyle(opts) {
async function updateUsercss(css) {
let oldVer = ucd.version;
let oldEtag = style.etag;
const m2 = (css || extractUsoaId(updateUrl)) &&
let m = (css || extractUsoaId(updateUrl)) &&
await getEmbeddedMeta(css || style.sourceCode);
if (m2 && m2.updateUrl) {
updateUrl = m2.updateUrl;
oldVer = m2[UCD].version || '0';
if (m && m.updateUrl) {
updateUrl = m.updateUrl;
oldVer = m[UCD].version || '0';
oldEtag = '';
} else if (css) {
return;
}
/* Using the more efficient HEAD+GET approach for greasyfork instead of GET+GET,
because if ETAG header changes it normally means an update so we don't need to
download meta additionally in a separate request. */
if ((m = updateUrl.match(rxGF))[5] === 'meta')
updateUrl = m[1] + 'user' + m[6];
if (oldEtag && oldEtag === await downloadEtag(updateUrl)) {
return Promise.reject(STATES.SAME_CODE);
}
Expand Down
4 changes: 2 additions & 2 deletions src/js/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const swPath = __.MV3 && `/${__.PAGE_BG}.js`;
export const favicon = host => `https://icons.duckduckgo.com/ip3/${host}.ico`;
/** Chrome 61.0.3161+ doesn't run content scripts on NTP https://crrev.com/2978953002/ */
export const chromeProtectsNTP = __.MV3 || CHROME >= 61;
export const rxGF = /^(https:\/\/)(?:update\.)?((?:greasy|sleazy)fork\.org\/scripts\/)(\d+)[^/]*\/code\/[^/]*\.user\.css$|$/;
export const rxGF = /^((https:\/\/)(?:update\.)?((?:greasy|sleazy)fork\.org\/scripts\/)(\d+)\/.*?\.)(meta|user)(\.css)$|$/;

export const uso = 'https://userstyles.org/';
export const usoApi = 'https://gateway.userstyles.org/styles/getStyle';
Expand Down Expand Up @@ -38,7 +38,7 @@ export const extractUswId = url =>
export const makeInstallUrl = (url, id) =>
url === 'usoa' || !id && (id = extractUsoaId(url)) ? `${usoa}style/${id}` :
url === 'usw' || !id && (id = extractUswId(url)) ? `${usw}style/${id}` :
url === 'gf' || !id && (id = rxGF.exec(url)) ? id[1] + id[2] + id[3] :
url === 'gf' || !id && (id = rxGF.exec(url)) ? id[2] + id[3] + id[4] :
'';

export const makeUpdateUrl = (url, id) =>
Expand Down

0 comments on commit 86deb15

Please sign in to comment.