Skip to content

Commit

Permalink
fix : replace 고침
Browse files Browse the repository at this point in the history
  • Loading branch information
moana16 committed Apr 13, 2023
1 parent 5fdb5a1 commit a9d0928
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions src/content/index.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,33 @@
console.info('pop-filterbubble-client content script');
const root = document.documentElement;
let originVideoListLength = 0;

//문제 2 : 이게 npm run dev 하지않아도 계속 소스를 받아오는데 왜그런지...?알수가없네...코드가 계속 돌아가는건가..?

let originLength = 0;
setInterval(() => {
const videoList = root.querySelectorAll('#text > a');
const linkToArr = Array.from(videoList);

let newVideoListLength = 0;
if (originVideoListLength === 0) {
let updateLength = 0;
if (originLength === 0) {
//만약 아예 받아온 데이터가 없으면!
newVideoListLength = getChannelIdList(linkToArr);
} else if (linkToArr.length > originVideoListLength) {
updateLength = getChannelIdList(linkToArr);
} else if (linkToArr.length > originLength) {
//새로운 값이 들어올 때
linkToArr.splice(0, originVideoListLength); //중복되는 값은 제거
newVideoListLength = getChannelIdList(linkToArr);
linkToArr.splice(0, originLength); //중복되는 값은 제거
updateLength = getChannelIdList(linkToArr);
}
//console.log(newVideoListLength);
originVideoListLength += newVideoListLength;
//console.log(originVideoListLength);
originLength += updateLength;
}, 5000);

function getChannelIdList(linkToArr: Array<Element>): number {
const newVideoList = linkToArr.map((a, idx) => {
if (a instanceof HTMLAnchorElement) {
let href = a.href;
let channelId = href.replace('https://www.youtube.com/', '').replace('channel/', '');
if (channelId !== '') return channelId;
const href = a.href;
const channelId = href.split('/').reverse()[0];
return channelId;
}
});
let newVideoListLength = newVideoList.length;
let updateLength = newVideoList.length;
console.log(newVideoList);
//여기서 서버에 전송하는 코드넣으면 될 듯?
return newVideoListLength;
return updateLength;
}

export {};

0 comments on commit a9d0928

Please sign in to comment.