Skip to content

Commit

Permalink
init project
Browse files Browse the repository at this point in the history
  • Loading branch information
yifu-yang committed Aug 16, 2021
1 parent abfcd92 commit 9084e86
Show file tree
Hide file tree
Showing 12 changed files with 421 additions and 0 deletions.
92 changes: 92 additions & 0 deletions ASoulCnki/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//let color = '#3aa757';


//chrome.runtime.onInstalled.addListener(() => {
// chrome.storage.sync.set({ color });
// console.log('Default background color set to %cgreen', `color: ${color}`);
//});
//https://api.bilibili.com/x/relation/followings?vmid=5468612&pn=1&ps=20&order=desc&order_type=attention&jsonp=jsonp&callback=__jp5


function renderPage() {
let userNames = document.querySelectorAll("a.name");
for (let user of userNames) {
let bid = user.dataset.usercardMid;
let tmp = document.getElementById("fanType" + bid)
if(tmp !=null){
tmp.remove();
}
let htmlText = "<button id=\"fanType" + bid + "\" data-bid=\"" + bid + "\">成分查询</button>"
user.parentElement.innerHTML = user.parentElement.innerHTML + htmlText;
let fanType = document.getElementById("fanType" + bid);
fanType.addEventListener("click", function (event) {
let ava = { "name": "顶晚人", "icon": "", "color": "#9AC8E2", "bid": "672346917" };
let bella = { "name": "贝极星", "icon": "", "color": "#DB7D74", "bid": "672353429" };
let carol = { "name": "皇珈骑士", "icon": "", "color": "#B8A6D9", "bid": "351609538" };
let diana = { "name": "嘉心糖", "icon": "", "color": "#E799B0", "bid": "672328094" };
let eileen = { "name": "乃淇淋", "icon": "", "color": "#576690", "bid": "672342685" };
let user = event.target;
let bid = user.dataset.bid;
var step;

console.log(step);
let followingList = "https://api.bilibili.com/x/relation/followings?vmid=" + bid + "&pn=1&ps=2000&order=desc&order_type=attention&jsonp=jsonp";//&callback=__jp5";
var xhr = new XMLHttpRequest();
xhr.open('get', followingList);
xhr.withCredentials = true;
xhr.send(null);
xhr.onreadystatechange = function () {
if (xhr.readyState != 4) return;
if (xhr.readyState == 4 && xhr.status == 200) {
var res = xhr.responseText;
var result = JSON.parse(res);
if (result.code === 22115) {
console.log("无法查看用户关注列表");
user.innerHTML = "未公开";
return;
}
let tags = "";
console.log(result.data.list);
result.data.list.forEach(element => {
if (String(element.mid) === ava.bid) {
tags += ava.name;
console.log("a");
}
if (String(element.mid) === bella.bid) {
tags += bella.name;
console.log("b");
}
if (String(element.mid) === carol.bid) {
tags += carol.name;
console.log("c");
}
if (String(element.mid) === diana.bid) {
tags += diana.name;
console.log("d");
}
if (String(element.mid) === eileen.bid) {
tags += eileen.name;
console.log("e");
}
});
if (tags === "") {
user.innerHTML = "纯路人";
} else {
user.innerHTML = tags;
}
}
}

});
}
}

chrome.action.onClicked.addListener((tab) => {
chrome.scripting.executeScript({
target: { tabId: tab.id },
function: renderPage
});
});



13 changes: 13 additions & 0 deletions ASoulCnki/button.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
button {
height: 30px;
width: 30px;
outline: none;
margin: 10px;
border: none;
border-radius: 2px;
}

button.current {
box-shadow: 0 0 0 2px white,
0 0 0 4px black;
}
Binary file added ASoulCnki/images/index.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions ASoulCnki/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<head>
<link rel="stylesheet" href="button.css">
<meta charset="UTF-8">
</head>
<body>
<button id="changeColor"></button>
<script src="popup.js"></script>
</body>
</html>
35 changes: 35 additions & 0 deletions ASoulCnki/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "Asoul Extensions",
"description": "mark asoul fan",
"version": "1.0",
"manifest_version": 3,
"action": {
//"default_popup": "index.html",
"default_icon": {
"16": "/images/index.png",
"32": "/images/index.png",
"48": "/images/index.png",
"128": "/images/index.png"
}
},
"commands": {
"_execute_action": {
"suggested_key": {
"default": "Ctrl+Shift+F",
"mac": "MacCtrl+Shift+F"
},
"description": "Opens index.html"
}
},
"background": {
"service_worker": "background.js"
},
"options_page": "options.html",
"permissions": ["storage", "activeTab", "scripting"],
"icons": {
"16": "/images/index.png",
"32": "/images/index.png",
"48": "/images/index.png",
"128": "/images/index.png"
}
}
15 changes: 15 additions & 0 deletions ASoulCnki/options.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html5 >
<head>
<link rel="stylesheet" href="button.css">
<meta http-equiv="Content-Type"content="text/html;charset=UTF-8">
</head>
<body>
<div id="buttonDiv">
</div>
<div>
<p>选择要标记的一个魂</p>
</div>
</body>
<script src="options.js" type="text/javascript"></script>
</html5>
61 changes: 61 additions & 0 deletions ASoulCnki/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

let page = document.getElementById("buttonDiv");
let selectedClassName = "current";
const presetButtonColors = ["#3aa757", "#e8453c", "#f9bb2d", "#4688f1"];

let ava = {"name":"顶晚人","icon":"","color":"#9AC8E2","bid":"672346917"};
let bella = {"name":"贝极星","icon":"","color":"#DB7D74","bid":"672353429"};
let carol = {"name":"皇珈骑士","icon":"","color":"#B8A6D9","bid":"351609538"};
let diana = {"name":"嘉心糖","icon":"","color":"#E799B0","bid":"672328094"};
let eileen = {"name":"乃淇淋","icon":"","color":"#576690","bid":"672342685"};

const asoul = [ava,bella,carol,diana,eileen];

// Reacts to a button click by marking the selected button and saving
// the selection
function handleButtonClick(event) {
// Remove styling from the previously selected color
let current = event.target.parentElement.querySelector(
`.${selectedClassName}`
);
if (current && current !== event.target) {
current.classList.remove(selectedClassName);
}

// Mark the button as selected
let color = event.target.dataset.color;
event.target.classList.add(selectedClassName);
console.log(color);
chrome.storage.sync.set({ color });
}

// Add a button to the page for each supplied color
function constructOptions(buttonColors) {
chrome.storage.sync.get("color", (data) => {
let currentColor = data.color;
// For each color we were provided…
for (let buttonColor of buttonColors) {
// …create a button with that color…
let button = document.createElement("button");
let name = document.createTextNode("name");
button.dataset.color = buttonColor.color;
name.textContent = buttonColor.name;
let idol = document.createElement("idol");
idol.appendChild(button);
idol.appendChild(name);
button.style.backgroundColor = buttonColor.color;
// …mark the currently selected color…
if (buttonColor === currentColor) {
button.classList.add(selectedClassName);
}

// …and register a listener for when that button is clicked
button.addEventListener("click", handleButtonClick);
page.appendChild(idol);
}
});
}

// Initialize the page by constructing the color options
//constructOptions(presetButtonColors);
constructOptions(asoul);
73 changes: 73 additions & 0 deletions ASoulCnki/popup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
let changeColor = document.getElementById("changeColor");



chrome.storage.sync.get("color", ({ color }) => {
changeColor.style.backgroundColor = color;
});

// When the button is clicked, inject setPageBackgroundColor into current page
changeColor.addEventListener("click", async () => {
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });

chrome.scripting.executeScript({
target: { tabId: tab.id },
function: setPageBackgroundColor,
});
});


// The body of this function will be executed as a content script inside the
// current page
function setPageBackgroundColor() {
chrome.storage.sync.get("color", ({ color }) => {
//document.body.style.backgroundColor = color;
let users = document.querySelectorAll("a.name");
let bid = "5468612";
let followingList = "https://api.bilibili.com/x/relation/followings?vmid=" + bid + "&pn=1&ps=2000&order=desc&order_type=attention&jsonp=jsonp";//&callback=__jp5";
var xhr = new XMLHttpRequest();
xhr.open('get', followingList);
xhr.withCredentials = true;
xhr.send(null);
xhr.onreadystatechange = function () {
if (xhr.readyState != 4) return;
if (xhr.readyState == 4 && xhr.status == 200) {
var res = xhr.responseText;
var result = JSON.parse(res);
console.log(result);
if(result.code === 22115){
console.log("无法查看用户关注列表")
}
result.data.list.forEach(element => {
if (element.mid === 351609538) {
console.log("皇珈骑士");
}
});
} else {
console.error('服务器错误');
}
}
/*for (let user of users) {
console.log(user);
let bid = user.dataset.usercardMid;
console.log(bid);
let followingList = "https://api.bilibili.com/x/relation/followings?vmid=" + bid + "&pn=1&ps=2000&order=desc&order_type=attention&jsonp=jsonp&callback=__jp5";
let ref = "https://space.bilibili.com/"+bid+"/fans/follow";
var xhr = new XMLHttpRequest();
xhr.open('get', followingList);
xhr.withCredentials = true;
xhr.setRequestHeader('Referer', ref);
xhr.send(null);
xhr.onreadystatechange = function () {
if (xhr.readyState != 4) return;
if (xhr.readyState == 4 && xhr.status == 200) {
var res = xhr.responseText;
console.log(res);
} else {
console.error('服务器错误');
}
}
}*/
});
}

83 changes: 83 additions & 0 deletions MarkFan/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@

function renderPage() {
let userNames = document.querySelectorAll("a.name");
for (let user of userNames) {
let bid = user.dataset.usercardMid;
let tmp = document.getElementById("fanType" + bid)
if(tmp !=null){
tmp.remove();
}
let htmlText = "<button id=\"fanType" + bid + "\" data-bid=\"" + bid + "\">成分查询</button>"
user.parentElement.innerHTML = user.parentElement.innerHTML + htmlText;
let fanType = document.getElementById("fanType" + bid);
fanType.addEventListener("click", function (event) {
let ava = { "name": "顶晚人", "icon": "", "color": "#9AC8E2", "bid": "672346917" };
let bella = { "name": "贝极星", "icon": "", "color": "#DB7D74", "bid": "672353429" };
let carol = { "name": "皇珈骑士", "icon": "", "color": "#B8A6D9", "bid": "351609538" };
let diana = { "name": "嘉心糖", "icon": "", "color": "#E799B0", "bid": "672328094" };
let eileen = { "name": "乃淇淋", "icon": "", "color": "#576690", "bid": "672342685" };
let user = event.target;
let bid = user.dataset.bid;
var step;

console.log(step);
let followingList = "https://api.bilibili.com/x/relation/followings?vmid=" + bid + "&pn=1&ps=2000&order=desc&order_type=attention&jsonp=jsonp";//&callback=__jp5";
var xhr = new XMLHttpRequest();
xhr.open('get', followingList);
xhr.withCredentials = true;
xhr.send(null);
xhr.onreadystatechange = function () {
if (xhr.readyState != 4) return;
if (xhr.readyState == 4 && xhr.status == 200) {
var res = xhr.responseText;
var result = JSON.parse(res);
if (result.code === 22115) {
console.log("无法查看用户关注列表");
user.innerHTML = "未公开";
return;
}
let tags = "";
console.log(result.data.list);
result.data.list.forEach(element => {
if (String(element.mid) === ava.bid) {
tags += "<p style=\"color:"+ava.color+"\">"+ava.name+"</p>";
console.log("a");
}
if (String(element.mid) === bella.bid) {
tags += "<p style=\"color:"+bella.color+"\">"+bella.name+"</p>";
console.log("b");
}
if (String(element.mid) === carol.bid) {
tags += "<p style=\"color:"+carol.color+"\">"+carol.name+"</p>";
console.log("c");
}
if (String(element.mid) === diana.bid) {
tags += "<p style=\"color:"+diana.color+"\">"+diana.name+"</p>";
console.log("d");
}
if (String(element.mid) === eileen.bid) {
tags += "<p style=\"color:"+eileen.color+"\">"+eileen.name+"</p>";
console.log("e");
}
});
if (tags === "") {
user.innerHTML = "纯路人";
} else {
user.innerHTML = tags;
}
}
}

});
}
}

chrome.action.onClicked.addListener((tab) => {
chrome.scripting.executeScript({
target: { tabId: tab.id },
function: renderPage
});
});



Binary file added MarkFan/images/index.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9084e86

Please sign in to comment.