Skip to content
This repository was archived by the owner on Sep 4, 2024. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# rewrite-overallブランチへようこそ🎃

このブランチはコードを最初から全部読み直して書き直そうという途方もなく壮大なプロジェクトです。

1周目では、

* 脱jQuery
* 脱onclick
* 脱コールバック地獄
* 重複してるやつや使ってないやつを消す

という極めて当たり前のやつをやっていきます。

# 以下いつものREADME

<img src="https://thedesk.top/img/top.png" width="300" align="left">
<img src="https://thedesk.top/img/desk.png" width="150" align="right">

Expand Down
2 changes: 1 addition & 1 deletion app/css/master.css
Original file line number Diff line number Diff line change
Expand Up @@ -605,4 +605,4 @@ textarea {
.linux .win,
.darwin .win {
display: none;
}
}
4 changes: 2 additions & 2 deletions app/js/common/about.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ts-check
//このソフトについて
function about() {
postMessage(["sendSinmpleIpc", "about"], "*")
}
}
document.getElementById('onClickAbout').addEventListener('click', about)
38 changes: 38 additions & 0 deletions app/js/common/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
async function getApi(start, at) {
let json = {}
let response = null
response = await fetch(start, {
method: 'GET',
headers: {
'content-type': 'application/json',
'Authorization': `Bearer ${at}`
}
})
if (!response.ok) {
response.text().then(function (text) {
setLog(response.url, response.status, text)
})
}
json = await response.json()
return json
}
async function postApi(url, body, at, ideKey) {
let json = {}
let response = null
response = await fetch(url, {
method: 'POST',
headers: {
'content-type': 'application/json',
'Authorization': `Bearer ${at}`,
'Idempotency-Key': ideKey
},
body: JSON.stringify(body)
})
if (!response.ok) {
response.text().then(function (text) {
setLog(response.url, response.status, text)
})
}
json = await response.json()
return json
}
70 changes: 35 additions & 35 deletions app/js/common/blurhash.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var digitCharacters = [
const digitCharacters = [
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
Expand All @@ -10,16 +10,16 @@ var digitCharacters = [
"|", "}", "~",
];
function decode83(str) {
var value = 0;
for (var i = 0; i < str.length; i++) {
var c = str[i];
var digit = digitCharacters.indexOf(c);
let value = 0;
for (let i = 0; i < str.length; i++) {
const c = str[i];
const digit = digitCharacters.indexOf(c);
value = value * 83 + digit;
}
return value;
}
function linearTosRGB(value) {
var v = Math.max(0, Math.min(1, value));
const v = Math.max(0, Math.min(1, value));
if (v <= 0.0031308) {
return Math.round(v * 12.92 * 255 + 0.5);
}
Expand All @@ -28,7 +28,7 @@ function linearTosRGB(value) {
}
}
function sRGBToLinear(value) {
var v = value / 255;
const v = value / 255;
if (v <= 0.04045) {
return v / 12.92;
}
Expand All @@ -37,18 +37,18 @@ function sRGBToLinear(value) {
}
}
function decodeDC(value) {
var intR = value >> 16;
var intG = (value >> 8) & 255;
var intB = value & 255;
const intR = value >> 16;
const intG = (value >> 8) & 255;
const intB = value & 255;
return [sRGBToLinear(intR), sRGBToLinear(intG), sRGBToLinear(intB)];
};
function sign(n) { return (n < 0 ? -1 : 1); }
function signPow(val, exp) { return sign(val) * Math.pow(Math.abs(val), exp); }
function decodeDC2(value, maximumValue) {
var quantR = Math.floor(value / (19 * 19));
var quantG = Math.floor(value / 19) % 19;
var quantB = value % 19;
var rgb = [
const quantR = Math.floor(value / (19 * 19));
const quantG = Math.floor(value / 19) % 19;
const quantB = value % 19;
const rgb = [
signPow((quantR - 9) / 9, 2.0) * maximumValue,
signPow((quantG - 9) / 9, 2.0) * maximumValue,
signPow((quantB - 9) / 9, 2.0) * maximumValue,
Expand All @@ -61,45 +61,45 @@ function decodeblur(blurhash, width, height, punch) {
console.error('too short blurhash');
return null;
}
var sizeFlag = decode83(blurhash[0]);
var numY = Math.floor(sizeFlag / 9) + 1;
var numX = (sizeFlag % 9) + 1;
var quantisedMaximumValue = decode83(blurhash[1]);
var maximumValue = (quantisedMaximumValue + 1) / 166;
const sizeFlag = decode83(blurhash[0]);
const numY = Math.floor(sizeFlag / 9) + 1;
const numX = (sizeFlag % 9) + 1;
const quantisedMaximumValue = decode83(blurhash[1]);
const maximumValue = (quantisedMaximumValue + 1) / 166;
if (blurhash.length !== 4 + 2 * numX * numY) {
console.error('blurhash length mismatch', blurhash.length, 4 + 2 * numX * numY);
return null;
}
var colors = new Array(numX * numY);
for (var i = 0; i < colors.length; i++) {
let colors = new Array(numX * numY);
for (let i = 0; i < colors.length; i++) {
if (i === 0) {
var value = decode83(blurhash.substring(2, 6));
const value = decode83(blurhash.substring(2, 6));
colors[i] = decodeDC(value);
}
else {
var value = decode83(blurhash.substring(4 + i * 2, 6 + i * 2));
const value = decode83(blurhash.substring(4 + i * 2, 6 + i * 2));
colors[i] = decodeDC2(value, maximumValue * punch);
}
}
var bytesPerRow = width * 4;
var pixels = new Uint8ClampedArray(bytesPerRow * height);
const bytesPerRow = width * 4;
let pixels = new Uint8ClampedArray(bytesPerRow * height);
for (var y = 0; y < height; y++) {
for (var x = 0; x < width; x++) {
var r = 0;
var g = 0;
var b = 0;
for (var j = 0; j < numY; j++) {
for (var i = 0; i < numX; i++) {
var basis = Math.cos(Math.PI * x * i / width) * Math.cos(Math.PI * y * j / height);
var color = colors[i + j * numX];
for (let j = 0; j < numY; j++) {
for (let i = 0; i < numX; i++) {
let basis = Math.cos(Math.PI * x * i / width) * Math.cos(Math.PI * y * j / height);
let color = colors[i + j * numX];
r += color[0] * basis;
g += color[1] * basis;
b += color[2] * basis;
}
}
var intR = linearTosRGB(r);
var intG = linearTosRGB(g);
var intB = linearTosRGB(b);
const intR = linearTosRGB(r);
const intG = linearTosRGB(g);
const intB = linearTosRGB(b);
pixels[4 * x + 0 + y * bytesPerRow] = intR;
pixels[4 * x + 1 + y * bytesPerRow] = intG;
pixels[4 * x + 2 + y * bytesPerRow] = intB;
Expand All @@ -109,9 +109,9 @@ function decodeblur(blurhash, width, height, punch) {
return pixels;
}
function parseBlur(blur) {
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var pixels = decodeblur(blur, 32, 32)
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
const pixels = decodeblur(blur, 32, 32)
const imageData = new ImageData(pixels, 32, 32);

ctx.putImageData(imageData, 0, 0);
Expand Down
Loading