-
Notifications
You must be signed in to change notification settings - Fork 1
/
popup.js
73 lines (69 loc) · 3.15 KB
/
popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
document.getElementById('get-text').addEventListener('click', function() {
console.log('get-text button was clicked');
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.runtime.sendMessage({
message: 'getArticleText',
tabId: tabs[0].id
}, response => {
console.log(response);
let text = response.text;
if (text && text.length > 10000) {
text = text.substring(0, 10000); // Keep only the first 10000 characters
}
document.getElementById('article-text').innerText = text;
document.getElementById('article-title').innerText = response.title;
alert(JSON.stringify(data, null, 2)); // Change this line
});
});
});
document.getElementById('save-api-key').addEventListener('click', function() {
let apiKey = document.getElementById('api-key').value;
chrome.storage.sync.set({apiKey: apiKey}, function() {
console.log('API key is saved');
document.getElementById('api-key').style.display = 'none';
document.getElementById('save-api-key').style.display = 'none';
alert("APIキーの最初の8文字: " + apiKey.substring(0, 8)); // APIキーの最初の8文字を表示
});
});
document.getElementById('save-notion-credentials').addEventListener('click', function() {
let secretKey = document.getElementById('notion-secret-key').value;
let databaseId = document.getElementById('notion-database-id').value;
chrome.storage.sync.set({secretKey: secretKey, databaseId: databaseId}, function() {
console.log('Notion credentials saved');
document.getElementById('notion-secret-key').style.display = 'none';
document.getElementById('notion-database-id').style.display = 'none';
document.getElementById('save-notion-credentials').style.display = 'none';
});
});
document.getElementById('check-api-key').addEventListener('click', function() {
chrome.storage.sync.get(['apiKey', 'secretKey', 'databaseId'], function(result) {
let alertMessage = '';
if (result.apiKey) {
alertMessage += "APIキーの最初の8文字: " + result.apiKey.substring(0, 8) + "\n";
} else {
alertMessage += "APIキーが保存されていません\n";
}
if (result.secretKey) {
alertMessage += "Notionシークレットキーの最初の10文字: " + result.secretKey.substring(0, 10) + "\n";
} else {
alertMessage += "Notionシークレットキーが保存されていません\n";
}
if (result.databaseId) {
alertMessage += "NotionデータベースID: " + result.databaseId + "\n";
} else {
alertMessage += "NotionデータベースIDが保存されていません\n";
}
alert(alertMessage);
});
});
chrome.storage.sync.get(['apiKey', 'secretKey', 'databaseId'], function(result) {
if (result.apiKey) {
document.getElementById('api-key').style.display = 'none';
document.getElementById('save-api-key').style.display = 'none';
}
if (result.secretKey && result.databaseId) {
document.getElementById('notion-secret-key').style.display = 'none';
document.getElementById('notion-database-id').style.display = 'none';
document.getElementById('save-notion-credentials').style.display = 'none';
}
});