Skip to content

Instantly share code, notes, and snippets.

@sigaloid
Last active January 10, 2022 16:13
Show Gist options
  • Save sigaloid/c07252eec41b0326f208986dfd5c10d4 to your computer and use it in GitHub Desktop.
Save sigaloid/c07252eec41b0326f208986dfd5c10d4 to your computer and use it in GitHub Desktop.
Custom share js + css
/* Parts taken from SPCSS
License: Copyright (c) 2020-2021 Susam Pal
https://github.com/susam/spcss/blob/master/LICENSE.md
*/
#menu {
border-right: 8px dashed;
border-radius: 10px;
border-image: linear-gradient(45deg, red, blue) 1;
width: 10px;
margin-right: 25px;
padding-right: 40px;
}
#layout {
max-width: 1800px;
}
#noteClippedFrom {
color: #8f9768;
}
#parentLink {
font-weight: bold;
font-size: 18px;
color: #66afe3;
border: 4px solid;
border-radius: 10px;
padding-left: 4px;
padding-right: 4px;
padding-top: 2px;
padding-bottom: 2px;
margin-bottom: 15px;
}
#main {
color: #d0cccc;
}
#buttons {
height: 30px;
padding: 10px 0 10px 0;
margin: 20px 0 20px 0;
color: #666;
border: 1px solid #ddd;
border-left: 0;
border-right: 0;
}
a:visited {
color: #1e00ed;
}
body {
background: #111;
color: #bbb;
font-family: helvetica, arial, sans-serif;
line-height: 1.5;
margin: 0 auto;
max-width: 80em;
padding: 0 1em;
}
h1,
h2,
h3,
h4,
h5,
h6 {
margin: 1.25em 0 0.5em 0;
line-height: 1.2;
}
a:link {
color: #009ded;
}
a:focus,
a:hover {
color: #03f;
}
a:active {
color: #e00;
}
h1 a:empty:before,
h2 a:empty:before,
h3 a:empty:before,
h4 a:empty:before,
h5 a:empty:before,
h6 a:empty:before {
content: "#";
}
h1 a:empty,
h2 a:empty,
h3 a:empty,
h4 a:empty,
h5 a:empty,
h6 a:empty {
visibility: hidden;
padding-left: 0.25em;
}
h1:hover a:empty,
h2:hover a:empty,
h3:hover a:empty,
h4:hover a:empty,
h5:hover a:empty,
h6:hover a:empty {
visibility: visible;
}
img {
max-width: 100%;
}
figure {
margin: 1em 0;
text-align: center;
}
figcaption {
font-size: small;
}
pre,
code,
samp,
kbd {
color: #71d22e;
font-family: monospace, monospace;
}
pre kbd {
color: #060;
}
blockquote {
background: #8d83ae6e;
padding: 0.5em;
}
pre {
padding: 0.5em;
background: #0000006e;
}
pre {
overflow: auto;
}
blockquote {
border-left: medium solid #ccc;
margin: 1em 0;
}
blockquote :first-child {
margin-top: 0;
}
blockquote :last-child {
margin-bottom: 0;
}
table {
border-collapse: collapse;
}
th,
td {
border: thin solid #999;
padding: 0.3em 0.4em;
text-align: left;
}
/* Toast bar */
#snackbar {
visibility: hidden;
min-width: 250px;
margin-left: -125px;
background-color: #333;
color: #fff;
text-align: center;
border-radius: 2px;
padding: 16px;
position: fixed;
z-index: 1;
left: 50%;
bottom: 30px;
}
#snackbar.show {
visibility: visible;
-webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
animation: fadein 0.5s, fadeout 0.5s 2.5s;
}
@-webkit-keyframes fadein {
from {bottom: 0; opacity: 0;}
to {bottom: 30px; opacity: 1;}
}
@keyframes fadein {
from {bottom: 0; opacity: 0;}
to {bottom: 30px; opacity: 1;}
}
@-webkit-keyframes fadeout {
from {bottom: 30px; opacity: 1;}
to {bottom: 0; opacity: 0;}
}
@keyframes fadeout {
from {bottom: 30px; opacity: 1;}
to {bottom: 0; opacity: 0;}
}
/* Toast bar */
/* Highlight on anchor */
:target {
background: #68684d;
}
var script = document.createElement("script");
script.src = "https://cdn.jsdelivr.net/npm/anchor-js/anchor.min.js";
script.type = "text/javascript";
script.onload = function () {
anchors.options = {
// visible: "always",
icon: "",
};
anchors.add();
anchors.add("#content li"); // Every element in content that is part of a list. Now you can link to a specific bullet point
};
document.getElementsByTagName("head")[0].appendChild(script);
document.body.onkeyup = function (e) {
if (e.keyCode == 37) {
if (prev === undefined) {
toast("No previous note!");
} else {
if (!loading) {
window.location.href = prev;
loading = true;
}
}
}
if (e.keyCode == 39) {
if (next === undefined) {
toast("No next note!");
} else {
if (!loading) {
window.location.href = next;
loading = true;
}
}
}
};
function toast(text) {
var x = document.getElementById("snackbar");
x.className = "show";
x.innerText = text;
setTimeout(function () {
x.className = x.className.replace("show", "");
}, 3000);
}
if (document.getElementById("menu") !== undefined && document.getElementById("menu").getElementsByTagName("li") !== undefined) {
var x = document.getElementById("menu").getElementsByTagName("li");
var num = 0;
var prev;
var next;
var loading; // stops a mildly annoying glitch when repeatedly clicking arrow
for (let i = 0; i <= x.length - 1; i++) {
if (x[i].children[0].innerHTML.includes("strong")) {
num = i;
break; //Break loop, always chooses first note in the case of cloned note.
}
}
var y = document.getElementById("main");
y.innerHTML += '<div id="snackbar"></div>';
if (x[num - 1] === undefined) {
var first = '<a class="disabled" style="float:left;">&lt; Previous</a>'; // There's no previous notes, so no link
} else {
var first = '<a style="float:left;" href="' + x[num - 1].children[0].children[0].href + '">&lt; Previous</a>';
prev = x[num - 1].children[0].children[0].href;
// Previous note exists, so set link to the href value of it
}
if (x[num + 1] === undefined || x[num + 1].children[0].children[0].href === undefined) {
var second = '<a class="disabled" style="float:right;">&gt; Next</a>'; // No next note, so no link
} else {
var second = '<a style="float:right;" href="' + x[num + 1].children[0].children[0].href + '">&gt; Next</a>';
next = x[num + 1].children[0].children[0].href;
// Next note exists, so set link to the href value of it.
}
y.innerHTML += '<br><br><div id="buttons">' + first + second + "</div>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment