port
This commit is contained in:
parent
e53ac4018c
commit
323779d351
17 changed files with 3376 additions and 62 deletions
|
|
@ -1,4 +1,8 @@
|
|||

|
||||
# Shiori injector
|
||||
|
||||
This is a fork of [linkding-injector](https://github.com/Fivefold/linkding-injector) to work with shiori.
|
||||
|
||||
Original readme below:
|
||||
|
||||
Community browser extension for the self-hosted [linkding](https://github.com/sissbruecker/linkding) bookmark service.
|
||||
|
||||
|
|
|
|||
8
build.sh
Normal file → Executable file
8
build.sh
Normal file → Executable file
|
|
@ -1,14 +1,14 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Update dependencies
|
||||
npm install
|
||||
pnpm install
|
||||
|
||||
# Run rollup build
|
||||
npm run build
|
||||
pnpm run build
|
||||
|
||||
# Lint extension, while excluding dev files
|
||||
npx web-ext lint --ignore-files .idea dist docs src web-ext-artifacts scss .gitignore *.sh *.ps1 *.iml *.js *.lock
|
||||
pnpx web-ext lint --ignore-files .idea dist docs src web-ext-artifacts scss .gitignore *.sh *.ps1 *.iml *.js *.lock
|
||||
# Build extension, while excluding dev files
|
||||
npx web-ext build --overwrite-dest --ignore-files .idea dist docs src web-ext-artifacts scss .gitignore *.sh *.ps1 *.iml *.js *.lock
|
||||
pnpx web-ext build --overwrite-dest --ignore-files .idea dist docs src web-ext-artifacts scss .gitignore *.sh *.ps1 *.iml *.js *.lock
|
||||
|
||||
echo "✅ Done"
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
{
|
||||
"manifest_version": 2,
|
||||
"name": "linkding injector",
|
||||
"name": "shiori injector",
|
||||
"version": "1.2.0",
|
||||
"description": "Injects search results from the linkding bookmark service into search pages like google and duckduckgo",
|
||||
"homepage_url": "https://github.com/fivefold/linkding-injector.git",
|
||||
"description": "Injects search results from the shiori bookmark service into search pages like google and duckduckgo",
|
||||
"homepage_url": "https://github.com/tezlm/shiori-injector",
|
||||
|
||||
"icons": {
|
||||
"19": "icons/logo_19.png",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Linkding Extension Options</title>
|
||||
<title>Shiori Extension Options</title>
|
||||
<link rel="stylesheet" href="../styles/spectre.css">
|
||||
<link rel="stylesheet" href="../styles/spectre-icons.css">
|
||||
<link rel="stylesheet" href="../styles/index.css">
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
var appTarget = document.getElementById('app');
|
||||
new linkding.Options({target: appTarget});
|
||||
new shiori.Options({target: appTarget});
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -1,11 +1,11 @@
|
|||
{
|
||||
"name": "linkding-injector",
|
||||
"name": "shiori-injector",
|
||||
"version": "1.1.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "linkding-injector",
|
||||
"name": "shiori-injector",
|
||||
"version": "1.1.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
|
|
|||
11
package.json
11
package.json
|
|
@ -1,17 +1,17 @@
|
|||
{
|
||||
"name": "linkding-injector",
|
||||
"name": "shiori-injector",
|
||||
"version": "1.2.0",
|
||||
"description": "Injects search results from the linkding bookmark service into search pages like google and duckduckgo",
|
||||
"description": "Injects search results from the shiori bookmark service into search pages like google and duckduckgo",
|
||||
"license": "MIT",
|
||||
"author": "Jakob Essbüchl",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/fivefold/linkding-injector.git"
|
||||
"url": "git+https://github.com/tezlm/shiori-injector.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/fivefold/linkding-injector/issues"
|
||||
"url": "https://github.com/tezlm/shiori-injector/issues"
|
||||
},
|
||||
"homepage": "https://github.com/fivefold/linkding-injector#readme",
|
||||
"homepage": "https://github.com/tezlm/shiori-injector#readme",
|
||||
"scripts": {
|
||||
"build": "rollup -c && sass scss/theme.scss build/searchInjection.css",
|
||||
"dev": "rollup -c -w && sass scss/theme.scss build/searchInjection.css"
|
||||
|
|
@ -27,6 +27,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"prettier": "^2.2.1",
|
||||
"sass": "^1.57.0",
|
||||
"web-ext": "^6.8.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
3309
pnpm-lock.yaml
generated
Normal file
3309
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -2,7 +2,7 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Linkding Extension Popup</title>
|
||||
<title>Shiori Extension Popup</title>
|
||||
<link rel="stylesheet" href="../styles/spectre.css">
|
||||
<link rel="stylesheet" href="../styles/spectre-icons.css">
|
||||
<link rel="stylesheet" href="../styles/spectre-exp.css">
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
var appTarget = document.getElementById('app');
|
||||
new linkding.Popup({target: appTarget});
|
||||
new shiori.Popup({target: appTarget});
|
||||
|
|
@ -12,7 +12,7 @@ export default [
|
|||
output: {
|
||||
sourcemap: true,
|
||||
format: 'iife',
|
||||
name: 'linkding',
|
||||
name: 'shiori',
|
||||
file: 'build/bundle.js'
|
||||
},
|
||||
plugins: [
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ $alternative-color-dark: #73f1eb;
|
|||
/* Dark theme specific */
|
||||
$dt-primary-button-color: #5761cb !default;
|
||||
|
||||
/* Custom additions to linkding variables */
|
||||
/* Custom additions to shiori variables */
|
||||
$alternative-color-light-theme: #05a6a3;
|
||||
$alternative-color-dark-light-theme: darken($alternative-color, 5%);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { getBrowser, openOptions } from "./browser";
|
||||
import { getConfiguration, isConfigurationComplete } from "./configuration";
|
||||
|
||||
import { search } from "./linkding";
|
||||
import { search } from "./shiori";
|
||||
|
||||
const browser = getBrowser();
|
||||
|
||||
|
|
@ -11,7 +11,7 @@ let portFromCS;
|
|||
function connected(p) {
|
||||
portFromCS = p;
|
||||
|
||||
// When the content script sends the search term, search on linkding and
|
||||
// When the content script sends the search term, search on shiori and
|
||||
// return results
|
||||
portFromCS.onMessage.addListener(function (m) {
|
||||
if (m.action == "openOptions") {
|
||||
|
|
@ -21,21 +21,23 @@ function connected(p) {
|
|||
} else if (isConfigurationComplete() == false) {
|
||||
portFromCS.postMessage({
|
||||
message:
|
||||
"Connection to your linkding instance is not configured yet! " +
|
||||
"Connection to your shiori instance is not configured yet! " +
|
||||
"Please configure the extension in the <a class='openOptions'>options</a>.",
|
||||
});
|
||||
} else {
|
||||
let config = getConfiguration();
|
||||
// Configuration is complete, execute a search on linkding
|
||||
search(m.searchTerm, { limit: config.resultNum })
|
||||
// Configuration is complete, execute a search on shiori
|
||||
search(m.searchTerm)
|
||||
.then((results) => {
|
||||
const bookmarkSuggestions = results.map((bookmark) => ({
|
||||
url: bookmark.url,
|
||||
title: bookmark.title || bookmark.website_title || bookmark.url,
|
||||
description: bookmark.description || bookmark.website_description,
|
||||
tags: bookmark.tag_names,
|
||||
date: bookmark.date_modified,
|
||||
}));
|
||||
const bookmarkSuggestions = results
|
||||
.slice(0, config.resultNum)
|
||||
.map((bookmark) => ({
|
||||
url: bookmark.url,
|
||||
title: bookmark.title || bookmark.url,
|
||||
description: bookmark.excerpt,
|
||||
tags: bookmark.tags,
|
||||
date: bookmark.modified,
|
||||
}));
|
||||
portFromCS.postMessage({
|
||||
results: bookmarkSuggestions,
|
||||
config: config,
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ export function openOptions() {
|
|||
opened and closed without saving options. The background script port closes
|
||||
seemingly indefinitely. The extension needs to be reloaded to fix it.
|
||||
|
||||
Since linkding injector does not use the svelte popup from linkding extension
|
||||
Since shiori injector does not use the svelte popup from shiori extension
|
||||
window.close can be safely omitted because there's no window to close
|
||||
*/
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<script>
|
||||
import { getConfiguration, saveConfiguration } from "./configuration";
|
||||
import { testConnection } from "./linkding";
|
||||
import { testConnection } from "./shiori";
|
||||
|
||||
let baseUrl;
|
||||
let token;
|
||||
|
|
@ -50,9 +50,9 @@
|
|||
<div class="divider" />
|
||||
<p>
|
||||
This is a companion extension for the <a
|
||||
href="https://github.com/sissbruecker/linkding">linkding</a
|
||||
href="https://github.com/sissbruecker/shiori">shiori</a
|
||||
> bookmark service. Before you can start using it you have to configure some basic
|
||||
settings, so that the extension can communicate with your linkding installation.
|
||||
settings, so that the extension can communicate with your shiori installation.
|
||||
</p>
|
||||
<form class="form" on:submit|preventDefault={handleSubmit}>
|
||||
<div class="form-group">
|
||||
|
|
@ -61,11 +61,11 @@
|
|||
class="form-input"
|
||||
type="text"
|
||||
id="input-base-url"
|
||||
placeholder="https://linkding.mydomain.com"
|
||||
placeholder="https://shiori.mydomain.com"
|
||||
bind:value={baseUrl}
|
||||
/>
|
||||
<div class="form-input-hint">
|
||||
The base URL of your linkding installation, <b>without</b> the
|
||||
The base URL of your shiori installation, <b>without</b> the
|
||||
<samp>/bookmark</samp> path or a trailing slash
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -79,8 +79,7 @@
|
|||
bind:value={token}
|
||||
/>
|
||||
<div class="form-input-hint">
|
||||
Used to authenticate against the linkding API. You can find this on your
|
||||
linkding settings page.
|
||||
Used to authenticate against the shiori API.
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ function getBrowser() {
|
|||
}
|
||||
|
||||
/* Sanitise input to prevent unwanted injection of html or even javascript
|
||||
through linkding search results, e.g. in the bookmark title or description
|
||||
through shiori search results, e.g. in the bookmark title or description
|
||||
*/
|
||||
function escapeHTML(str) {
|
||||
let p = document.createElement("p");
|
||||
|
|
@ -40,7 +40,7 @@ port.onMessage.addListener(function (m) {
|
|||
<div id="navbar">
|
||||
<a id="ld-logo">
|
||||
<img src=${browser.runtime.getURL("icons/logo.svg")} />
|
||||
<h1>linkding injector</h1>
|
||||
<h1>shiori injector</h1>
|
||||
</a>
|
||||
<a id="ld-options" class="openOptions">
|
||||
<img class="ld-settings" src=${browser.runtime.getURL(
|
||||
|
|
@ -76,21 +76,21 @@ port.onMessage.addListener(function (m) {
|
|||
themeClass = theme; // "dark" for dark theme, "light" for light theme
|
||||
}
|
||||
|
||||
// URL of the configured linkding instance (including search term)
|
||||
let linkdingUrl =
|
||||
// URL of the configured shiori instance (including search term)
|
||||
let shioriUrl =
|
||||
m.config.baseUrl +
|
||||
(searchTerm.length > 0 ? `/bookmarks?q=${searchTerm}` : "/");
|
||||
(searchTerm.length > 0 ? `/bookmarks?keywords=${searchTerm}` : "/");
|
||||
|
||||
htmlString += `
|
||||
<div id="bookmark-list-container" class="${searchEngine} ${themeClass}">
|
||||
<div id="navbar">
|
||||
<a id="ld-logo" href="${linkdingUrl}">
|
||||
<a id="ld-logo" href="${shioriUrl}">
|
||||
<img src=${browser.runtime.getURL("icons/logo.svg")} />
|
||||
<h1>linkding injector</h1>
|
||||
<h1>shiori injector</h1>
|
||||
</a>
|
||||
<div id="results_amount">
|
||||
Found <span>${m.results.length}</span> ${
|
||||
m.results.length == 1 ? "result" : "results"
|
||||
m.results.length === 1 ? "result" : "results"
|
||||
}.
|
||||
</div>
|
||||
<a id="ld-options" class="openOptions">
|
||||
|
|
@ -118,7 +118,7 @@ port.onMessage.addListener(function (m) {
|
|||
<span class="tags">
|
||||
${bookmark.tags
|
||||
.map((tag) => {
|
||||
return "<a>#" + escapeHTML(tag) + "</a>";
|
||||
return "<a>#" + escapeHTML(tag.name) + "</a>";
|
||||
})
|
||||
.join(" ")}
|
||||
</a>
|
||||
|
|
@ -134,7 +134,7 @@ port.onMessage.addListener(function (m) {
|
|||
});
|
||||
htmlString += `</ul></div>`;
|
||||
} else {
|
||||
console.error("linkding injector: no message and no search results");
|
||||
console.error("shiori injector: no message and no search results");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,47 +3,46 @@ import { getConfiguration } from "./configuration";
|
|||
export async function getTags() {
|
||||
const configuration = getConfiguration();
|
||||
|
||||
return fetch(`${configuration.baseUrl}/api/tags/?limit=1000`, {
|
||||
return fetch(`${configuration.baseUrl}/api/tags`, {
|
||||
headers: {
|
||||
Authorization: `Token ${configuration.token}`,
|
||||
"X-Session-Id": configuration.token,
|
||||
},
|
||||
}).then((response) => {
|
||||
if (response.status === 200) {
|
||||
return response.json().then((body) => body.results);
|
||||
return response.json();
|
||||
}
|
||||
return Promise.reject(`Error loading tags: ${response.statusText}`);
|
||||
});
|
||||
}
|
||||
|
||||
export async function search(text, options) {
|
||||
export async function search(text) {
|
||||
const configuration = getConfiguration();
|
||||
const q = encodeURIComponent(text);
|
||||
const limit = options.limit || 100;
|
||||
|
||||
return fetch(
|
||||
`${configuration.baseUrl}/api/bookmarks/?q=${q}&limit=${limit}`,
|
||||
`${configuration.baseUrl}/api/bookmarks/?keyword=${q}&page=1`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Token ${configuration.token}`,
|
||||
"X-Session-Id": configuration.token,
|
||||
},
|
||||
}
|
||||
).then((response) => {
|
||||
if (response.status === 200) {
|
||||
return response.json().then((body) => body.results);
|
||||
return response.json().then((body) => body.bookmarks);
|
||||
}
|
||||
return Promise.reject(`Error searching bookmarks: ${response.statusText}`);
|
||||
});
|
||||
}
|
||||
|
||||
export async function testConnection(configuration) {
|
||||
return fetch(`${configuration.baseUrl}/api/bookmarks/?limit=1`, {
|
||||
return fetch(`${configuration.baseUrl}/api/bookmarks/?page=1`, {
|
||||
headers: {
|
||||
Authorization: `Token ${configuration.token}`,
|
||||
Authorization: configuration.token,
|
||||
},
|
||||
})
|
||||
.then((response) =>
|
||||
response.status === 200 ? response.json() : Promise.reject(response)
|
||||
)
|
||||
.then((body) => !!body.results)
|
||||
.then((body) => !!body.bookmarks)
|
||||
.catch(() => false);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue