home

my firefox custom homepage
Log | Files | Refs | README | git clone https://git.ne02ptzero.me/git/home

commit 1966c45ceefb4668c9f6a630d1b03369deacffd1
parent 1fe6f489845291108a8c471f30f51acbb7413fc2
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Tue,  3 Oct 2017 23:53:18 +0200

[CORE] ADD: Huge optimization:

We now compile the site statically, with a minifier.
I modified the way we read bangs and shortcuts, it is now much easier to
edit for an user.
Official bangs are now in bangs/bangs.json, and customs one in
bangs/bangs_custom.json.
Same thing for shortcuts (shortcuts/shortcuts{_custom}.json)
Instead of a bloated node script, i coded a small web server C, which
deliver the static site much faster.

Before this patch, the site would load in ~300ms without cache.
With this patch, the site is now loading in 0-1ms without cache.

Signed-off-by: Ne02ptzero <louis@ne02ptzero.me>

Diffstat:
A.gitignore | 1+
AMakefile | 9+++++++++
MREADME.md | 13++++++-------
Abangs/bangs.json | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Abangs/bangs_custom.json | 4++++
Ahome.html | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dindex.html | 74--------------------------------------------------------------------------
Mmain.css | 23+----------------------
Mmain.js | 126+++++++++++++------------------------------------------------------------------
Amake_site.sh | 18++++++++++++++++++
Aserv | 0
Aserver.c | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dserver.js | 6------
Ashortcuts/shortcuts.json | 20++++++++++++++++++++
Ashortcuts/shortcuts_custom.json | 1+
15 files changed, 289 insertions(+), 215 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1 @@ +index.html diff --git a/Makefile b/Makefile @@ -0,0 +1,9 @@ +all: + gcc -O3 server.c -o serv + ./make_site.sh + +serve: + sudo ./serv + +clean: + rm -f serv diff --git a/README.md b/README.md @@ -8,15 +8,14 @@ git clone https://github.com/Ne02ptzero/home Install: ``` -npm install connect serve-static +sudo npm install html-minifier -g ``` -## Launch +## Compile & Launch ``` -sudo node server.js +make && sudo make serve ``` -Note that you can run the server as a normal user if you don't use the ```80``` -port. +Since the site is statically compiled, one must re-do ```make``` on any changes. Go to [the home page](127.0.0.1) @@ -46,7 +45,7 @@ in the progress bar, he will be redirected to facebook. See all shortcuts in the main.js file, ```shortcuts``` array ## Adding a custom bang -One must edit the ```bangs``` array in main.js, and add an entry in it: +One must edit the ```bangs/bangs_custom.json``` file, and add an entry in it: ``` "bang": { "url": "https://site.com/search/%s", @@ -56,7 +55,7 @@ One must edit the ```bangs``` array in main.js, and add an entry in it: With this entry, if one types ```bang test``` in his input, he will be redirected to ```https://site.com/search/test```. ## Adding a custom shortcuts -One must edit the ```shortcuts``` array in main.js, and add an entry in it: +One must edit the ```shortcuts/bangs_shortcuts.json``` file, and add an entry in it: ``` "sh": "https://shortcuts.com" ``` diff --git a/bangs/bangs.json b/bangs/bangs.json @@ -0,0 +1,64 @@ +"g": { + "url": "https://www.google.com/search?q=%s", + "help": "Google" +}, +"gi": { + "url": "https://www.google.com/search?q=%s&tbm=isch", + "help": "Google Images" +}, +"yt": { + "url": "https://www.youtube.com/results?search_query=%s", + "help": "YouTube" +}, +"r": { + "url": "https://www.reddit.com/search?q=%s", + "help": "Reddit" +}, +"i": { + "url": "https://profile.intra.42.fr/searches/search?query=%s", + "help": "42 Intra Search" +}, +"iu": { + "url": "https://profile.intra.42.fr/users/%s", + "help": "42 Intra User" +}, +"gt": { + "url": "https://github.com/search?utf8=✓&q=%s&type=", + "help": "Github" +}, +"st": { + "url": "https://stackoverflow.com/search?q=%s", + "help": "Stack Overflow" +}, +"hn": { + "url": "https://hn.algolia.com/?query=%s", + "help": "Hacker News" +}, +"lbs": { + "url": "https://lobste.rs/search?utf8=✓&q=%s&what=stories&order=relevance", + "help": "Lobste.rs" +}, +"wk": { + "url": "https://en.wikipedia.org/w/index.php?search=%s", + "help": "Wikipedia" +}, +"sr": { + "url": "https://reddit.com/r/%s", + "help": "Subreddit" +}, +"man": { + "url": "http://man.he.net/?topic=%s&section=all", + "help": "Man Pages" +}, +"gt": { + "url": "https://translate.google.com/?hl=fr#fr/en/%s", + "help": "Google traduction" +}, +"tpb": { + "url": "https://thepiratebay.org/search/%s/0/99/0", + "help": "The Pirate Bay" +}, +"deb": { + "url": "https://packages.debian.org/search?keywords=%s&searchon=names&suite=stable&section=all", + "help": "Debian package" +}, diff --git a/bangs/bangs_custom.json b/bangs/bangs_custom.json @@ -0,0 +1,4 @@ +"yb": { + "url": "https://your-bang-goes-here.com/%s", + "help": "Your shortcut" +} diff --git a/home.html b/home.html @@ -0,0 +1,71 @@ +<!DOCTYPE html> +<html> + <head> + <title>Home</title> + <meta charset="UTF-8"> + </head> + <body onload="startTime()"> + <div id="main-container"> + <div id="content-container"> + <img src=" data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABEwAAAS6BAMAAACy5OGNAAAAElBMVEX///7///8AAAABAQEDAwP+/v4Vhil9AAAAAXRSTlMAQObYZgAAAAFiS0dEAIgFHUgAAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfhCgMNDTI8aGlWAAANvElEQVR42u3ccZKaPBjAYbmB6PQALicQvYEn6P0v0zqys0qtbDaJAfL8pjP0DzbAy6P9vnYmm80ca9pRr08fn73dqIYwESbCRJhowUyECSbCRHUwyXevPiyYYIIJJssZ/ZumjAkmmGCCCSaYYIKJMMEEE0wwwQQTTDDBBBNMMMEEE0wwWYA1TDDBRJgIE2GCCSaYYIIJJphgggkmmAgTYYIJJphgggkmmGCCCSaYyJSFiTARJpIkfxjMKZuqY4IJJphgggkmmGCCCSaYYIIJJhUxaUMeFhNMMMEEE0zmwqSu/6j71tOuZSSYYIIJJphgggkmmFTBpH0WJphgggkmmGCCCSaYYIIJJphgggkmmGCCCSaYYIIJJphgggkmmGCCCSa1MgkfbS1MYj9fmGCCCSaYYJKTScV0MMEEE0wwadqJMMEEE0yK/98IJphggknKQWCCyetBbN/77bUwJkvaWwoTTDDBBBNMMMEEE/9qvLAwESbCRJgIE0wwwQQTTDDBRJgIE2EiTIQ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MMMHkDQUO8xTUMe7NDatcvnm1wNW9+3xMPoI6xDEZVum/eTVMMMEEE0wwwQQTTDDBRJgIE0wwwQQTTDDBBBNMMMEEE0yECSaYYIIJJphgggkmmGCCCSbCBBNMMMEEE0wwwQQTTDDBBBNhIkwwyVWTlEk3tdfE5etwvv32/pCWiQ1M5spksv7r0A2yHg6YYIIJJphgggkmmAgTYYIJJphgggkmmGCCCSaYCBNhggkmmGCCCSaYYIIJJpgIE2GCCSaYYIIJJphgggkmmGCCiTARJphgggkmmKyFyahdSSaBm+xgggkmmGCCCSaYYIIJJphgIkyECSaYYIIJJphgggkmmGAiTIQJJphgggkmmGCCCSaYYCJMhIkwwQQTTDDBBBNMMMEEE0yEiTDB5J21yw0LTDDBBBNMMMEEE0wwESbCRJhgggkmmGCCCSaYYCJMhIkwwQQTTDDBBBNMMMEEE0yEiTARJphgggkmmGCCCSaYCBNhIkwwweZ7eTuYYIIJJphgggkmwkSYCBNhggkmmGCCCSaYCBNhIkyECSaYYIIJJphgggkmwkSYCBNhggkmmGCCCSaYCBNhIkyECSarZfLPliPbr0Pz9xcmmLSTO9NgggkmmGAiTISJMBEmmGCCCSaYYIIJJpgIE2EiTDDBBBNMMMEEE0wwESbCRJgIE0wwwQQTTDDBRJgIE2EiTDDBBBNMMKmmJorF0xXvDm3y1bUSJgFfXZhgggkmmGCCiTARJsJEmAgTTDDBBBNMhIkwESbCRJhgggkmmGCCCSbCRJgIE2EiTDDBBBNMMBEmwkSYCBNJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJ0sL6Ay/nT63B5ZRZAAAAAElFTkSuQmCC" /> + <h1>/home</h1> + <form action="javascript: submit();"> + <ul class='search'> + <li class='first'>/search/</li> + <li><input id="search" type="text" placeholder="ggl" autofocus autocomplete="off"></li> + </ul> + </form> + <div id="column-container"> + <!-- + EDIT LINKS HERE + --> + <ul> + <li>/work</li> + <li><a href="https://labo-sns.stormshield.eu/reviewboard/dashboard/?view=to-group&group=NGIUTM">/w/reviews</a></li> + <li><a href="https://labo-sns.stormshield.eu/cgit/index/">/w/git</a></li> + <li><a href="https://wearestormshield.talkspirit.com/#/l/home?clip=all&type=all&view=wall&_k=srnj5s">/w/we_are</a></li> + <li><a href="https://mantis.stormshield.eu/login_page.php">/w/mantis</a></li> + </ul> + <ul> + <li>/code</li> + <li><a href="https://github.com">/c/github</a></li> + <li><a href="https://fw.senc.io/">/c/senc-io</a></li> + </ul> + <ul> + <li>/social</li> + <li><a href="https://youtube.com">/s/yt</a></li> + <li><a href="https://twitter.com">/s/twt</a></li> + <li><a href="https://facebook.com">/s/fb</a></li> + <li><a href="https://e2r13.slack.com/messages/C03B5MYF9">/s/slck</a></li> + </ul> + <ul> + <li>/reddit</li> + <li><a href="https://reddit.com/r/all">/r/*</a></li> + <li><a href="https://reddit.com/r/france">/r/fr</a></li> + <li><a href="https://reddit.com/r/wow">/r/wow</a></li> + <li><a href="https://reddit.com/r/linux">/r/nux</a></li> + </ul> + <ul> + <li>/tech</li> + <li><a href="https://news.ycombinator.com/">/t/hn</a></li> + <li><a href="https://lwn.net/">/t/lwn</a></li> + <li><a href="https://korben.info/">/t/kbn</a></li> + <li><a href="https://lobste.rs/">/t/lbst</a></li> + </ul> + <ul> + <li>/fun</li> + <li><a href="https://xkcd.com/">/f/xkcd</a></li> + <li><a href="https://danstonchat.com/latest.html">/f/dtc</a></li> + <li><a href="https://www.twitch.tv/">/f/twitch</a></li> + </ul> + <ul> + <li>/music</li> + <li><a href="https://plug.dj/tastycat#playlists">/m/pdj</a><li> + <li><a href="https://soundcloud.com/stream">/m/sc</a><li> + </ul> + </div> + </div> + </div> + <div id="time"></div> + <div class='help'><a href="#" onclick="show_help()">Help</a></div> + <div id='show_help'></div> diff --git a/index.html b/index.html @@ -1,74 +0,0 @@ -<!DOCTYPE html> -<html> - <head> - <title>Home</title> - <meta charset="UTF-8"> - <link rel="icon" href="favicon.png" type="image/icon"> - <link rel="stylesheet" href="main.css"> - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <script type="text/javascript" src="main.js"></script> - </head> - <body onload="startTime()"> - <div id="main-container"> - <div id="content-container"> - <img src="mask.png" /> - <h1>/home</h1> - <form action="javascript: submit();"> - <ul class='search'> - <li class='first'>/search/</li> - <li><input id="search" type="text" placeholder="ggl" autofocus autocomplete="off"></li> - </ul> - </form> - <div id="column-container"> - <ul> - <li>/work</li> - <li><a href="https://labo-sns.stormshield.eu/reviewboard/dashboard/?view=to-group&group=NGIUTM">/w/reviews</a></li> - <li><a href="https://labo-sns.stormshield.eu/cgit/index/">/w/git</a></li> - <li><a href="https://wearestormshield.talkspirit.com/#/l/home?clip=all&type=all&view=wall&_k=srnj5s">/w/we_are</a></li> - <li><a href="https://mantis.stormshield.eu/login_page.php">/w/mantis</a></li> - </ul> - <ul> - <li>/code</li> - <li><a href="https://github.com">/c/github</a></li> - <li><a href="https://fw.senc.io/">/c/senc-io</a></li> - </ul> - <ul> - <li>/social</li> - <li><a href="https://youtube.com">/s/yt</a></li> - <li><a href="https://twitter.com">/s/twt</a></li> - <li><a href="https://facebook.com">/s/fb</a></li> - <li><a href="https://e2r13.slack.com/messages/C03B5MYF9">/s/slck</a></li> - </ul> - <ul> - <li>/reddit</li> - <li><a href="https://reddit.com/r/all">/r/*</a></li> - <li><a href="https://reddit.com/r/france">/r/fr</a></li> - <li><a href="https://reddit.com/r/wow">/r/wow</a></li> - <li><a href="https://reddit.com/r/linux">/r/nux</a></li> - </ul> - <ul> - <li>/tech</li> - <li><a href="https://news.ycombinator.com/">/t/hn</a></li> - <li><a href="https://lwn.net/">/t/lwn</a></li> - <li><a href="https://korben.info/">/t/kbn</a></li> - <li><a href="https://lobste.rs/">/t/lbst</a></li> - </ul> - <ul> - <li>/fun</li> - <li><a href="https://xkcd.com/">/f/xkcd</a></li> - <li><a href="https://danstonchat.com/latest.html">/f/dtc</a></li> - <li><a href="https://www.twitch.tv/">/f/twitch</a></li> - </ul> - <ul> - <li>/music</li> - <li><a href="https://plug.dj/tastycat#playlists">/m/pdj</a><li> - <li><a href="https://soundcloud.com/stream">/m/sc</a><li> - </ul> - </div> - </div> - </div> - <div id="time"></div> - <div class='help'><a href="#" onclick="show_help()">Help</a></div> - <div id='show_help'></div> - </body> -</html> diff --git a/main.css b/main.css @@ -1,18 +1,3 @@ -/* - * Minimal Firefox Homepage - * - * Author: clyde80 - * Website: https://github.com/clyde80 - * Created on: February 05, 2017 - * Updated on: February 06, 2017 - * - * Colors: - * Red: #A26A5B - * Yellow: #FAE8A4 - * Green: #406158 - * Black: #211716 - * - */ html, body { margin: 0; padding: 0; @@ -21,11 +6,6 @@ html, body { font-family: 'Inconsolata', monospace; } -/* - * Use the following code to center stuff in browser window in future. - * - * Source: (https://www.w3.org/Style/Examples/007/center-example) - */ #main-container { top: 0; left: 0; @@ -40,7 +20,6 @@ html, body { display: table-cell; vertical-align: middle; } -/* End of centering stuff in browser window. */ @media only screen and (min-width: 481px) { #search { @@ -120,7 +99,7 @@ img { .search .first { font-size: 14px; - margin-right: -12px; + margin-right: -5px; } .help { diff --git a/main.js b/main.js @@ -1,109 +1,19 @@ -var bangs = { - "g": { - "url": "https://www.google.com/search?q=%s", - "help": "Google" - }, - "gi": { - "url": "https://www.google.com/search?q=%s&tbm=isch", - "help": "Google Images" - }, - "yt": { - "url": "https://www.youtube.com/results?search_query=%s", - "help": "YouTube" - }, - "r": { - "url": "https://www.reddit.com/search?q=%s", - "help": "Reddit" - }, - "i": { - "url": "https://profile.intra.42.fr/searches/search?query=%s", - "help": "42 Intra Search" - }, - "iu": { - "url": "https://profile.intra.42.fr/users/%s", - "help": "42 Intra User" - }, - "gt": { - "url": "https://github.com/search?utf8=✓&q=%s&type=", - "help": "Github" - }, - "st": { - "url": "https://stackoverflow.com/search?q=%s", - "help": "Stack Overflow" - }, - "hn": { - "url": "https://hn.algolia.com/?query=%s", - "help": "Hacker News" - }, - "lbs": { - "url": "https://lobste.rs/search?utf8=✓&q=%s&what=stories&order=relevance", - "help": "Lobste.rs" - }, - "wk": { - "url": "https://en.wikipedia.org/w/index.php?search=%s", - "help": "Wikipedia" - }, - "sr": { - "url": "https://reddit.com/r/%s", - "help": "Subreddit" - }, - "man": { - "url": "http://man.he.net/?topic=%s&section=all", - "help": "Man Pages" - }, - "gt": { - "url": "https://translate.google.com/?hl=fr#fr/en/%s", - "help": "Google traduction" - }, - "tpb": { - "url": "https://thepiratebay.org/search/%s/0/99/0", - "help": "The Pirate Bay" - }, - "deb": { - "url": "https://packages.debian.org/search?keywords=%s&searchon=names&suite=stable&section=all", - "help": "Debian package" - } -}; - -var shortcuts = { - "gh": "https://github.com", - "github": "https://github.com", - "hn": "https://news.ycombinator.com/", - "fb": "https://www.facebook.com/?_rdr", - "facebook": "https://www.facebook.com/?_rdr", - "tw": "https://twitter.com", - "twitter": "https://twitter.com", - "ds": "https://discordapp.com/channels/@me", - "discord": "https://discordapp.com/channels/@me", - "lwn": "https://lwn.net/", - "kbn": "https://korben.info/", - "korben": "https://korben.info/", - "sc": "https://soundcloud.com/stream", - "yt": "https://www.youtube.com/", - "youtube": "https://www.youtube.com/", - "yts": "https://www.youtube.com/feed/subscriptions", - "re": "https://www.reddit.com/", - "r": "https://www.reddit.com/", - "reddit": "https://www.reddit.com/", - "wk": "https://en.wikipedia.org/wiki/Main_Page" -}; - function submit() { - url = document.getElementById('search').value + url = document.getElementById('search').value; if (url.startsWith("http")) window.location.href = url; else { - res = url.split(" ") + res = url.split(" "); if (bangs[res[0]] && res.length > 1) { - term = url.substring(res[0].length + 1, url.len) - url = bangs[res[0]].url.replace(/%s/i, term) - window.location.href = url + term = url.substring(res[0].length + 1, url.len); + url = bangs[res[0]].url.replace(/%s/i, term); + window.location.href = url; } else if (shortcuts[url]) { - window.location.href = shortcuts[url] + window.location.href = shortcuts[url]; } else { @@ -125,28 +35,32 @@ function startTime() { } function checkTime(i) { - if (i < 10) {i = "0" + i}; // add zero in front of numbers < 10 + if (i < 10) {i = "0" + i}; return i; } -help_show = 0 +help_show = 0; +html = ""; function show_help() { if (help_show == 0) { - html = "<ul>" - for (var key in bangs) + if (html === "") { - b = bangs[key] - html += "<li><div class='shortcut'>"+ key + "</div> "+ b["help"] +"</li>" + html = "<ul>"; + for (var key in bangs) + { + b = bangs[key]; + html += "<li><div class='shortcut'>"+ key + "</div> "+ b["help"] +"</li>"; + } + html += "</ul>"; } - html += "</ul>" - document.getElementById("show_help").innerHTML = html - document.getElementById("show_help").style.display = "block" + document.getElementById("show_help").innerHTML = html; + document.getElementById("show_help").style.display = "block"; } else { - document.getElementById("show_help").style.display = "none" + document.getElementById("show_help").style.display = "none"; } help_show = help_show == 0 ? 1 : 0; } diff --git a/make_site.sh b/make_site.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +cat home.html > index.html +echo "<style>" >> index.html +cat main.css >> index.html +echo "</style>" >> index.html +echo "<script>" >> index.html +echo "var bangs = {" >> index.html +cat bangs/bangs.json >> index.html +cat bangs/bangs_custom.json >> index.html +echo "}; var shortcuts = {" >> index.html +cat shortcuts/shortcuts.json >> index.html +cat shortcuts/shortcuts_custom.json >> index.html +echo "};" >> index.html +cat main.js >> index.html +echo "</script></body></html>" >> index.html +html-minifier --collapse-boolean-attributes --collapse-whitespace --decode-entities --html5 --minify-css --minify-js --process-conditional-comments --remove-attribute-quotes --remove-comments --remove-optional-tags --remove-redundant-attributes --remove-script-type-attributes --remove-style-link-type-attributes --remove-tag-whitespace --sort-attributes --sort-class-name --trim-custom-fragments --use-short-doctype index.html > index.min.html +mv index.min.html index.html diff --git a/serv b/serv Binary files differ. diff --git a/server.c b/server.c @@ -0,0 +1,74 @@ +#define _GNU_SOURCE +#include <unistd.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/stat.h> +#include <string.h> +#include <netinet/in.h> +#include <sys/socket.h> +#include <assert.h> + +# define INDEX "index.html" + +char *read_index(void) +{ + int fd = open(INDEX, O_RDONLY); + struct stat index_stat; + char *ret = NULL; + + if (fd == -1) + { + fprintf(stderr, "Can't open " INDEX " file\n"); + exit(1); + } + fstat(fd, &index_stat); + ret = malloc(index_stat.st_size + 1); + read(fd, ret, index_stat.st_size); + ret[index_stat.st_size] = 0; + close(fd); + return ret; +} + +void serve(char *content) +{ + struct sockaddr_in addr; + struct stat stat_buf; + socklen_t addrlen; + int c_sock, n_sock; + size_t content_size = strlen(content); + + c_sock = socket(AF_INET, SOCK_STREAM, 0); + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = INADDR_ANY; + addr.sin_port = htons(80); + + assert(bind(c_sock, (struct sockaddr *)&addr, sizeof(addr)) == 0); + + while (1) + { + listen(c_sock, 10); + n_sock = accept(c_sock, (struct sockaddr *)&addr, &addrlen); + write(n_sock, content, content_size); + close(n_sock); + } + + close(c_sock); +} + +int main(void) +{ + char *file; + char *send = NULL; + + file = read_index(); + asprintf(&send, "HTTP/1.1 200 OK\n\ +Content-length: %zu\n\ +Content-type: text/html\n\ +\n\ +%s", strlen(file), file); + free(file); + serve(send); + free(send); + return 0; +} diff --git a/server.js b/server.js @@ -1,6 +0,0 @@ -var connect = require('connect'); -var serveStatic = require('serve-static'); - -connect().use(serveStatic(__dirname)).listen(80, function() { - console.log("Server running on 80 port."); -}) diff --git a/shortcuts/shortcuts.json b/shortcuts/shortcuts.json @@ -0,0 +1,20 @@ +"gh": "https://github.com", +"github": "https://github.com", +"hn": "https://news.ycombinator.com/", +"fb": "https://www.facebook.com/?_rdr", +"facebook": "https://www.facebook.com/?_rdr", +"tw": "https://twitter.com", +"twitter": "https://twitter.com", +"ds": "https://discordapp.com/channels/@me", +"discord": "https://discordapp.com/channels/@me", +"lwn": "https://lwn.net/", +"kbn": "https://korben.info/", +"korben": "https://korben.info/", +"sc": "https://soundcloud.com/stream", +"yt": "https://www.youtube.com/", +"youtube": "https://www.youtube.com/", +"yts": "https://www.youtube.com/feed/subscriptions", +"re": "https://www.reddit.com/", +"r": "https://www.reddit.com/", +"reddit": "https://www.reddit.com/", +"wk": "https://en.wikipedia.org/wiki/Main_Page", diff --git a/shortcuts/shortcuts_custom.json b/shortcuts/shortcuts_custom.json @@ -0,0 +1 @@ +"ysh": "https://your-shortcut-goes-here.com"