1
0
mirror of https://github.com/Pomax/BezierInfo-2.git synced 2025-08-27 18:20:24 +02:00

this rename is absolutely stupid

This commit is contained in:
Pomax
2020-08-20 13:01:32 -07:00
parent 59fdafb2c5
commit d92e370bd1
470 changed files with 22 additions and 9 deletions

51
docs/js/site/referrer.js Normal file
View File

@@ -0,0 +1,51 @@
/**
* This script collects information on visitors, based
* on their client session. It finds out which page they
* were on when they go there, and by virtue of sending
* that information to the logger, their IP. This is
* information that you're sending already, anyway, but
* I want you to know that this is what's going on.
*
* Which is why this script is not obfuscated. It simply
* grabs your document.referrer value, which (unless Do
* Not Track is enabled) will contain the location of
* the page you were on before you clicked a link to this
* page, and GETs that to my logger. That GET operation
* comes from your computer, so will have your IP as part
* of the HTTP headers.
*
* And that's all I really care about, because I want to
* know how many people visit this page, and roughly where
* they're from (gasp! IPs can be turned into rough
* geographical location O_O).
*
* If you want to know what logger.php looks like, hit up
* github. It's in referrer/logger.php
*
*/
(function referrer(l) {
var page = l.substring(l.lastIndexOf("/") + 1).replace(".html", "");
page = page || "index.html";
// we don't care about file or localhost, for obvious reasons
var loc = window.location.toString();
if (loc.indexOf("file:///") !== -1) return;
if (loc.indexOf("localhost") !== -1) return;
// right, continue
var url = "http://pomax.nihongoresources.com/pages/bezierinfo/logger.php";
var xhr = new XMLHttpRequest();
xhr.open(
"GET",
url +
"?" +
"referrer=" +
encodeURIComponent(document.referrer) +
"&for=" +
page,
true
);
try {
xhr.send(null);
} catch (e) {
/* you don't care about this error, and I can't see it, so why would we do anything with it? */
}
})(window.location.toString());

View File

@@ -0,0 +1,91 @@
/**
* This file is responsible for making sure that the reddit, hn, twitter, etc. linkouts
* are updated to reflect the section someone is reading, rather than always pointing to
* base article itself.
*/
(function tryToBind() {
if (!document.querySelector(`map[name="rhtimap"]`)) {
return setTimeout(tryToBind, 300);
}
class Tracker {
constructor() {
this.section = false;
this.hash = false;
this.socials = ["rdt", "hn", "twt"];
}
update(data) {
this.section = data.section;
this.hash = data.hash;
this.socials.forEach((social) => {
var area = document.querySelector(`map area.sclnk-${social}`);
area.href = this[`get_${social}`]();
});
}
get url() {
return encodeURIComponent(
`https://pomax.github.io/bezierinfo${this.hash ? this.hash : ""}`
);
}
getTitle() {
var title = `A Primer on Bézier Curves`;
if (this.section) {
title = `${this.section}-${title}`;
}
return encodeURIComponent(title);
}
get_rdt() {
var title = this.getTitle();
var text = encodeURIComponent(
`A free, online book for when you really need to know how to do Bézier things.`
);
return `https://www.reddit.com/submit?url=${this.url}&title=${title}&text=${text}`;
}
get_hn() {
var title = this.getTitle();
return `https://news.ycombinator.com/submitlink?u=${this.url}&t=${title}`;
}
get_twt() {
var text =
encodeURIComponent(
`Reading "${this.section}" by @TheRealPomax over on `
) + this.url;
return `https://twitter.com/intent/tweet?original_referer=${this.url}&text=${text}&hashtags=bezier,curves,maths`;
}
}
// we set the section and fragmentid based on which ever section's heading is nearest
// the top of the screen, either just off-screen or in-screen
var tracker = new Tracker();
var anchors = Array.from(document.querySelectorAll("section h2 a"));
var sections = anchors.map((a) => a.parentNode);
var sectionData = sections.map((section) => {
return {
section: section.textContent,
hash: section.querySelector("a").hash,
};
});
window.addEventListener(
"scroll",
function (evt) {
var min = 99999999999999999;
var element = false;
sections.forEach((s, pos) => {
var v = Math.abs(s.getBoundingClientRect().top);
if (v < min) {
min = v;
element = pos;
}
});
tracker.update(sectionData[element]);
},
{ passive: true }
);
})();