Skip to content

Commit

Permalink
fix: show real url for relative externals
Browse files Browse the repository at this point in the history
  • Loading branch information
tophf committed Nov 15, 2024
1 parent 7a1ef0c commit 212a1dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/background/utils/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,8 @@ export async function parseScript(src) {
if (!getScriptHome(script) && isRemote(src.from)) {
script.custom.homepageURL = src.from;
}
if (isRemote(src.url)) script.custom.lastInstallURL = src.url;
// Allowing any http url including localhost as the user may keep multiple scripts there
if (isValidHttpUrl(src.url)) script.custom.lastInstallURL = src.url;
script.custom.tags = script.custom.tags?.split(/\s+/).map(normalizeTag).filter(Boolean).join(' ').toLowerCase();
if (!srcUpdate) storage.mod.remove(getScriptUpdateUrl(script, { all: true }) || []);
buildPathMap(script, src.url);
Expand Down
24 changes: 18 additions & 6 deletions src/common/ui/externals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div v-if="!install || all.length > 1" class="select"
ref="$list" focusme @keydown="moveIndex" @scroll="saveScroll"
:data-has-main="install ? '' : null">
<dl v-for="([type, url, contents], i) of all" :key="i"
<dl v-for="([type, url, fullUrl, contents], i) of all" :key="i"
class="flex"
:class="{
active: index === i,
Expand All @@ -13,7 +13,7 @@
@click="contents !== false && (index = i)">
<dt v-text="type"/>
<dd class="ellipsis flex-1">
<a :href="url" target="_blank">&nearr;</a>
<a :href="fullUrl" target="_blank">&nearr;</a>
<span v-text="decodeURIComponent(url)"/>
</dd>
<dd v-if="contents" v-text="formatLength(contents, type)" class="ml-2"/>
Expand All @@ -40,7 +40,8 @@

<script setup>
import { computed, nextTick, onActivated, onDeactivated, ref, watchEffect } from 'vue';
import { dataUri2text, formatByteLength, i18n, makeDataUri, sendCmdDirectly } from '@/common';
import { dataUri2text, formatByteLength, getFullUrl, i18n, makeDataUri, sendCmdDirectly }
from '@/common';
import VmCode from '@/common/ui/code';
import { focusMe, hasKeyModifiers } from '@/common/ui/index';
Expand All @@ -55,11 +56,22 @@ const data = ref({});
const all = computed(() => {
const { code, deps = dependencies.value, url: mainUrl } = props.install || {};
const { require = [], resources = {} } = props.value.meta || {};
const { custom: { pathMap = {} } = {}, meta } = props.value;
const { require = [], resources = {} } = meta || {};
return [
...mainUrl ? [[i18n('editNavCode'), mainUrl, code]] : [],
...require.map(url => ['@require', url, deps[`0${url}`]]),
...Object.entries(resources).map(([id, url]) => [`@resource ${id}`, url, deps[`1${url}`]]),
...require.map(url => [
'@require',
url,
pathMap[url] || getFullUrl(url, mainUrl),
deps[`0${url}`],
]),
...Object.entries(resources).map(([id, url]) => [
`@resource ${id}`,
url,
pathMap[url] || getFullUrl(url, mainUrl),
deps[`1${url}`],
]),
];
});
Expand Down

0 comments on commit 212a1dc

Please sign in to comment.