Skip to content

Commit 896dab1

Browse files
committed
occasional CORS error fix
1 parent ee29431 commit 896dab1

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

background.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,25 @@ async function hyAddUrl(importUrl, tags)
5353
);
5454
}
5555

56-
async function hyApiMain(importUrl, hash, tags, urls=[], notes={})
56+
async function getHash(url) {
57+
const imageResponse = await fetch(url);
58+
if (imageResponse.status !== 200) {
59+
throw new Error(`Failed to get ${url} with status code ${imageResponse.status}`);
60+
//return '0';
61+
}
62+
const image = await imageResponse.arrayBuffer();
63+
const hashBuffer = await crypto.subtle.digest('SHA-256', image);
64+
const hashArray = Array.from(new Uint8Array(hashBuffer));
65+
66+
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
67+
return hashHex;
68+
}
69+
70+
async function hyApiMain(importUrl, tags, urls=[], notes={})
5771
{
5872
const addUrlResponse = await hyAddUrl(importUrl, tags);
73+
74+
const hash = await getHash(importUrl);
5975
const associateUrlResponse = await hyAssociateUrl(hash, urls);
6076
const setNotesResponse = await hySetNotes(hash, notes);
6177

@@ -75,7 +91,7 @@ chrome.runtime.onMessage.addListener(
7591
console.log(sender);
7692
if (msg.action == 'hydrusAPI')
7793
{
78-
hyApiMain(msg.importUrl, msg.imageHash, msg.tags, msg.urls, msg.notes)
94+
hyApiMain(msg.importUrl, msg.tags, msg.urls, msg.notes)
7995
.then((response) => {
8096
console.log(response);
8197
callback(response);

content.js

-18
Original file line numberDiff line numberDiff line change
@@ -116,29 +116,12 @@ function getComment()
116116
return commentElement.innerText;
117117
}
118118

119-
async function getHash()
120-
{
121-
const fetchUrl = getUrl();
122-
const imageResponse = await fetch(fetchUrl);
123-
if (imageResponse.status !== 200) {
124-
throw new Error(`Failed to get ${fetchUrl} with status code ${imageResponse.status}`);
125-
//return '0';
126-
}
127-
const image = await imageResponse.arrayBuffer();
128-
const hashBuffer = await crypto.subtle.digest('SHA-256', image);
129-
const hashArray = Array.from(new Uint8Array(hashBuffer));
130-
131-
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
132-
return hashHex;
133-
}
134-
135119
async function hyPost()
136120
{
137121
hyButton.innerHTML = '[ ' + 'faHy Working' + ' ] ';
138122
hyButton.removeEventListener('click', hyPost, true);
139123

140124
const importUrl = getUrl();
141-
const imageHash = await getHash();
142125
const tags = getTags();
143126
const urls = getUrlsFromTags(tags);
144127
const notes =
@@ -150,7 +133,6 @@ async function hyPost()
150133
chrome.runtime.sendMessage({
151134
action: 'hydrusAPI',
152135
importUrl: importUrl,
153-
imageHash: imageHash,
154136
tags: tags,
155137
urls: urls,
156138
notes: notes

manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"128": "images/icon-128.png"
2121
}
2222
},
23-
"host_permissions": ["http://127.0.0.1/*"],
23+
"host_permissions": ["http://127.0.0.1/*", "https://d.furaffinity.net/art/*"],
2424
"permissions": ["scripting", "activeTab"],
2525
"content_scripts": [
2626
{

0 commit comments

Comments
 (0)