This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Check that the request is coming from my site. | |
if (!isset($_SERVER['HTTP_REFERER']) || !stristr(strtolower($_SERVER['HTTP_REFERER']), strtolower($_SERVER['SERVER_NAME']))) { | |
http_response_code(403); | |
exit; | |
} | |
// There has to be a URL provided in the query string. | |
if (!isset($_GET['url'])) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.body.addEventListener('click', function(event) { | |
var target = event.target.closest('a[href]'); | |
if (!target) return; | |
var href = encodeURIComponent(target.getAttribute('href')); | |
if (!href.startsWith('http')) return | |
if (href.includes('archive.org')) return | |
var url = `/redirect.php?url=${href}`; | |
if (target.closest('.h-entry') && target.closest('.h-entry').querySelector('time.dt-published[datetime]')) { | |
var date = encodeURIComponent(target.closest('.h-entry').querySelector('time.dt-published').getAttribute('datetime')); | |
url += `&date=${date}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Pass a string of text into the function to convert @@ usernames. */ | |
function autoLinkMastodonUsernames($string) { | |
return preg_replace( | |
'/@?\b([A-Za-zŽžÀ-ÿ0-9._%+-]+)@([A-Za-zŽžÀ-ÿ0-9.-]+\.[A-Za-zŽžÀ-ÿ]{2,})\b/i', | |
'<a href="https://$2/@$1">$0</a>', | |
$string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (win, doc) { | |
'use strict'; | |
if (!doc.querySelectorAll || !win.Intl || !win.Intl.RelativeTimeFormat) { | |
// doesn't cut the mustard. | |
return; | |
} | |
var rtf = new Intl.RelativeTimeFormat('en', { | |
localeMatcher: 'best fit', | |
numeric: 'always', | |
style: 'long' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Pass in an array of data with keys for `status` | |
e.g. | |
postToMastodon(array( | |
'status' => 'Hello, world!' | |
)); | |
Include `reply_url` if you're responding to a post |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication | |
// http://creativecommons.org/publicdomain/zero/1.0/ | |
(function (win,doc) { | |
'use strict'; | |
if (!win.FileReader || !win.addEventListener || !doc.querySelectorAll) { | |
// doesn't cut the mustard. | |
return; | |
} | |
doc.querySelectorAll('input[type="file"][accept="image/*"]').forEach( function (fileInput) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function curlURL($url) { | |
$return = array(); | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_VERBOSE, 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/jonathantneal/closest/blob/master/src/index.js | |
var ElementPrototype = window.Element.prototype; | |
if (typeof ElementPrototype.matches !== 'function') { | |
ElementPrototype.matches = ElementPrototype.msMatchesSelector || ElementPrototype.mozMatchesSelector || ElementPrototype.webkitMatchesSelector || function matches(selector) { | |
var element = this; | |
var elements = (element.document || element.ownerDocument).querySelectorAll(selector); | |
var index = 0; | |
while (elements[index] && elements[index] !== element) { | |
++index; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication | |
// http://creativecommons.org/publicdomain/zero/1.0/ | |
(function (win, doc) { | |
// Cut the mustard. | |
if (!win.localStorage) return; | |
// You should probably use a more specific selector than this. | |
var textarea = doc.querySelector('textarea'); | |
// The key for the key/value pair in localStorage is the current URL. | |
var key = win.location.href; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication | |
// http://creativecommons.org/publicdomain/zero/1.0/ | |
/* | |
This function takes two arguments: | |
element: a reference to a DOM node in the document e.g. a button. | |
feedbackContent: a string of text or HTML. | |
An example of usage would be: | |
document.querySelector('button').addEventListener('click', function() { |
NewerOlder