-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
119 lines (108 loc) · 3.56 KB
/
index.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// alert("Optimize News... Waiting..")
let all_url = document.querySelectorAll('a[href*="new"]');
var api_url = 'https://summary-h24fed2hha-el.a.run.app';
var metadata =document.createElement('meta');
metadata.httpEquiv='Content-SecurityPolicy';
metadata.content='upgrade-insecure-request';
(document.head||document.documentElement).appendChild(metadata);
function unicodeToChar(text) {
return text.replace(/\\u[\dA-F]{4}/gi,
function (match) {
return String.fromCharCode(parseInt(match.replace(/\\u/g, ''), 16));
});
}
function inputTooltip(obj) {
var title = document.createElement("span");
title.textContent = "title : ";
var doc = document.createElement("div");
doc.textContent = "summary :" + obj.document;
title.classList.add("tooltiptext");
// doc.classList.add('tooltiptext');
var inp = obj.childNodes[0];
title.appendChild(doc);
obj.insertBefore(title, inp);
}
// const spawn = require('child_process').spawn;
async function get_url_document(obj) {
await fetch(api_url, {
method: 'POST',
mode:'cors',
headers: {
'Content-Type': 'application/json',
},
referrer:'client',
referrerPolicy:'origin',
body: JSON.stringify({
'newsurl': obj.href
})
}).then(data=>data.json()).then(data2=>{console.log(data2.title);obj.news_title=data2.title;obj.news_document=data2.document})
};
function get_url_document2(obj) {
fetch(api_url, {
method: 'POST',
mode:'cors',
headers: {
'Content-Type': 'application/json',
},
referrer:'client',
referrerPolicy:'origin',
body: JSON.stringify({
'newsurl': obj.href
})
}).then(data=>data.json()).then(data2=>{console.log(a.title);
console.log(a.document);
console.log(data2.title);
obj.news_title=data2.title;
obj.news_document=data2.document})
};
async function short_news(obj){
await fetch('https://8080-a453e8ef-a5f4-481a-ac8c-f0e4364d1764.cs-asia-east1-jnrc.cloudshell.dev/handle_post', {
method: 'POST',
mode:'cors',
headers: {
'Content-Type': 'application/json',
},
referrer:'client',
referrerPolicy:'origin',
body: JSON.stringify({
'document':obj.newsDoc
})
}).then(data=>data.json()).then(data2=>{obj.summary=data2.text})
return obj;
}
// all_url.forEach((a, i) => {
var a = all_url[20];
a.classList.add("tooltip")
// get_url_document2(a);
fetch('https://summary-h24fed2hha-el.a.run.app', {
method: 'POST',
mode:'cors',
headers: {
'Content-Type': 'application/json',
},
referrer:'client',
referrerPolicy:'origin',
body: JSON.stringify({
'newsurl': a.href
})
}).then(data=>data.json()).then(data2=>{a.newsDoc = data2.document;a.newsTit=data2.title;
fetch('http://ec2-13-124-98-178.ap-northeast-2.compute.amazonaws.com/handle_post', {
method: 'POST',
headers: {
'Content-Type': 'application/json',"User-Agent":'Mozilla/5.0',"Accept":"*/*"
},
body: JSON.stringify({
'document':a.newsDoc
})
}).then(data3=>data3.json()).then(data4=>{
console.log(data4);
a.summary=data4.text
})
});
// a.newsDoc = 기사제목
// a.newsTit = 기사 본문
// setTimeout(get_url_document,1000,a)
// console.log(NewsData);
short_news(a);
inputTooltip(a);
// })