mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2024-11-22 08:07:30 +00:00
Add userscript
This commit is contained in:
parent
637060279d
commit
3cbe4647e1
30
src/site/api/userscripts.js
Normal file
30
src/site/api/userscripts.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
const fs = require("fs").promises
|
||||||
|
const constants = require("../../lib/constants")
|
||||||
|
|
||||||
|
// Instances are here rather than loaded dynamically because adding more requires the script to auto-update, which requires a version increase
|
||||||
|
const instanceList = new Set([
|
||||||
|
"https://bibliogram.art",
|
||||||
|
"https://bibliogram.snopyta.org",
|
||||||
|
"https://bibliogram.pussthecat.org",
|
||||||
|
"https://bibliogram.13ad.de",
|
||||||
|
"https://bibliogram.nixnet.services",
|
||||||
|
"https://bibliogram.hamster.dance",
|
||||||
|
"https://bibliogram.ggc-project.de"
|
||||||
|
])
|
||||||
|
|
||||||
|
instanceList.add(constants.website_origin)
|
||||||
|
|
||||||
|
module.exports = [
|
||||||
|
{
|
||||||
|
route: "/userscripts/unblock.user.js", methods: ["GET"], code: async () => {
|
||||||
|
let script = await fs.readFile("html/userscripts/unblock.user.js", "utf8")
|
||||||
|
script = script.replace(/<website_origin>/g, constants.website_origin)
|
||||||
|
script = script.replace(/\/\/ <instance_match_list>/g, [...instanceList.values()].map(i => `// @match ${i}/u/*`).join("\n"))
|
||||||
|
return {
|
||||||
|
statusCode: 200,
|
||||||
|
contentType: "application/javascript",
|
||||||
|
content: script
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
101
src/site/html/userscripts/unblock.user.js
Normal file
101
src/site/html/userscripts/unblock.user.js
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
// ==UserScript==
|
||||||
|
// @name Bibliogram unblocker
|
||||||
|
// @namespace <website_origin>
|
||||||
|
// <instance_match_list>
|
||||||
|
// @downloadURL <website_origin>/userscripts/unblock.user.js
|
||||||
|
// @updateURL <website_origin>/userscripts/unblock.user.js
|
||||||
|
// @grant none
|
||||||
|
// @version 1.0
|
||||||
|
// @author cloudrac3r
|
||||||
|
// ==/UserScript==
|
||||||
|
|
||||||
|
|
||||||
|
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||||
|
//
|
||||||
|
// Be sure to press "Confirm installation" to install this script!
|
||||||
|
//
|
||||||
|
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||||
|
|
||||||
|
|
||||||
|
function q(s) {
|
||||||
|
return document.querySelector(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
function addChild(parent, tag, content, className) {
|
||||||
|
const e = document.createElement(tag)
|
||||||
|
e.textContent = content
|
||||||
|
if (className) e.className = className
|
||||||
|
parent.appendChild(e)
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyStyles(element, styles) {
|
||||||
|
for (const key of Object.keys(styles)) {
|
||||||
|
element.style[key] = styles[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (q("#bibliogram-identifier-blocked")) {
|
||||||
|
const scriptStatus = addChild(q("#dynamic-status-area"), "p", "Unblocker script is processing...", "explanation")
|
||||||
|
applyStyles(scriptStatus, {border: "solid orange", borderWidth: "1px 0px", padding: "10px", marginTop: "20px", textAlign: "center"})
|
||||||
|
function flashBackground() {
|
||||||
|
scriptStatus.animate([
|
||||||
|
{"background": "rgba(255, 255, 255, 0.15)", easing: "ease-in"},
|
||||||
|
{"background": "rgba(255, 255, 255, 0)"}
|
||||||
|
], 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
const username = q("#data").getAttribute("data-username")
|
||||||
|
|
||||||
|
fetch(`https://www.instagram.com/${username}/`).then(res => {
|
||||||
|
|
||||||
|
if (res.status === 200) {
|
||||||
|
res.text().then(text => {
|
||||||
|
const id = (text.match(/"id":"([0-9]+)"/) || [])[1]
|
||||||
|
|
||||||
|
if (id) {
|
||||||
|
const params = new URLSearchParams()
|
||||||
|
params.append("username", username)
|
||||||
|
params.append("user_id", id)
|
||||||
|
|
||||||
|
fetch(`${window.location.origin}/api/suggest_user/v1`, {
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/x-www-form-urlencoded"
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
body: params.toString()
|
||||||
|
}).then(res => {
|
||||||
|
if (res.status === 201) {
|
||||||
|
scriptStatus.textContent = "Done! Please wait to be redirected..."
|
||||||
|
flashBackground();
|
||||||
|
} else {
|
||||||
|
res.json().then(data => {
|
||||||
|
console.log(data)
|
||||||
|
alert(data.message)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
scriptStatus.textContent = "Submission request error: " + (error && error.message || error)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
scriptStatus.textContent = "Couldn't extract ID from page."
|
||||||
|
flashBackground();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (res.status === 302) {
|
||||||
|
scriptStatus.textContent =
|
||||||
|
"Your network is blocked too. To be unblocked, wait several hours without making any more attempts."
|
||||||
|
+" VPNs, proxies and Tor are always blocked."
|
||||||
|
flashBackground();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (res.status === 404) {
|
||||||
|
scriptStatus.textContent = "This profile doesn't exist."
|
||||||
|
flashBackground();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
@ -19,9 +19,18 @@ html#bibliogram-identifier-blocked
|
|||||||
.width-block
|
.width-block
|
||||||
#dynamic-status-area
|
#dynamic-status-area
|
||||||
|
|
||||||
p If you use Mac or Linux, you can unblock this profile now! Run this in your favourite terminal:
|
|
||||||
pre curl -Ss #{website_origin}/u/#{username}/unblock.sh | $SHELL
|
|
||||||
ul
|
ul
|
||||||
|
li
|
||||||
|
| #[a(href="#unblock-on-mac-or-linux") Unblock with shell], no download, Mac and Linux only
|
||||||
|
.hidden-section#unblock-on-mac-or-linux
|
||||||
|
p Open the Terminal application, then paste this code:
|
||||||
|
pre curl -Ss #{website_origin}/u/#{username}/unblock.sh | $SHELL
|
||||||
|
li
|
||||||
|
| #[a(href="#unblock-with-userscript") Unblock automatically with userscript], any modern browser
|
||||||
|
.hidden-section#unblock-with-userscript
|
||||||
|
p If you don't already have a userscript manager, install #[a(href="https://violentmonkey.github.io/get-it/") Violentmonkey] (open source) or #[a(href="https://www.tampermonkey.net/") Tampermonkey] (closed source)
|
||||||
|
p #[a(href="/userscripts/unblock.user.js") Open this link.] You should be prompted to install the script. Press "Confirm installation" on that page.
|
||||||
|
p Reload this page.
|
||||||
li To learn more, #[a(href="https://github.com/cloudrac3r/bibliogram/wiki/Rate-limits") read about blocking.]
|
li To learn more, #[a(href="https://github.com/cloudrac3r/bibliogram/wiki/Rate-limits") read about blocking.]
|
||||||
li You may be able to avoid this by #[a(href="https://github.com/cloudrac3r/bibliogram/wiki/Instances") browsing on another instance.]
|
li You may be able to avoid this by #[a(href="https://github.com/cloudrac3r/bibliogram/wiki/Instances") browsing on another instance.]
|
||||||
li It's good to read scripts to see what they do. #[a(href=`${website_origin}/u/${username}/unblock.sh`) Read ./unblock.sh]
|
li It's good to read scripts to see what they do. #[a(href=`${website_origin}/u/${username}/unblock.sh`) Read ./unblock.sh]
|
||||||
|
@ -466,6 +466,13 @@ body
|
|||||||
margin-top: 10px
|
margin-top: 10px
|
||||||
font-size: 20px
|
font-size: 20px
|
||||||
|
|
||||||
|
.hidden-section
|
||||||
|
display: none
|
||||||
|
padding: 10px
|
||||||
|
|
||||||
|
&:target
|
||||||
|
display: block
|
||||||
|
|
||||||
.homepage
|
.homepage
|
||||||
display: flex
|
display: flex
|
||||||
flex-direction: column
|
flex-direction: column
|
||||||
|
Loading…
Reference in New Issue
Block a user