transform unhide_func from macro to included html

This commit is contained in:
leafee98 2023-10-24 15:10:19 +08:00
parent eb13d4f4a0
commit 354a0a958a
2 changed files with 29 additions and 33 deletions

28
template/hide.html Normal file
View file

@ -0,0 +1,28 @@
<script>
function unhide(seed, arr) {
seed %= 1000000007;
const str_arr = [];
for (let i = 0; i < arr.length; i++) {
str_arr.push((((arr[i] - seed) % 256) + 256) % 256)
seed = seed * seed % 1000000007;
}
const ui8_arr = new Uint8Array(str_arr);
const str = new TextDecoder().decode(ui8_arr);
return str;
}
function unhide_permalink() {
let anchors = document.querySelectorAll("a[hidden_permalink][seed]")
for (let anchor of anchors) {
let arr = new Array();
for (let n of anchor.getAttribute("hidden_permalink").split(",")) {
arr.push(Number(n));
};
let seed = Number(anchor.getAttribute("seed"))
anchor.href = unhide(seed, arr);
}
}
</script>

View file

@ -1,37 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
{% macro unhide_func() %}
<script>
function unhide(seed, arr) {
seed %= 1000000007;
const str_arr = [];
for (let i = 0; i < arr.length; i++) {
str_arr.push((((arr[i] - seed) % 256) + 256) % 256)
seed = seed * seed % 1000000007;
}
const ui8_arr = new Uint8Array(str_arr);
const str = new TextDecoder().decode(ui8_arr);
return str;
}
function unhide_permalink() {
let anchors = document.querySelectorAll("a[hidden_permalink][seed]")
for (let anchor of anchors) {
let arr = new Array();
for (let n of anchor.getAttribute("hidden_permalink").split(",")) {
arr.push(Number(n));
};
let seed = Number(anchor.getAttribute("seed"))
anchor.href = unhide(seed, arr);
}
}
</script>
{% endmacro %}
{% macro render_item(item) %} {% macro render_item(item) %}
{% set class_str = "item" %} {% set class_str = "item" %}
@ -84,7 +52,7 @@
<meta name="viewport" content="width=device-width,minimum-scale=1"> <meta name="viewport" content="width=device-width,minimum-scale=1">
<link ref="canonical" href="{{canonical_link}}" /> <link ref="canonical" href="{{canonical_link}}" />
{{ unhide_func() }} {% include "hide.html" %}
</head> </head>
<style>{% include "reset.css" %}</style> <style>{% include "reset.css" %}</style>