2022-07-27 00:48:24 +08:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
2022-07-29 17:37:56 +08:00
|
|
|
<title>热搜榜单</title>
|
2022-07-27 00:48:24 +08:00
|
|
|
<style>
|
|
|
|
* {
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
html,
|
|
|
|
body {
|
|
|
|
height: 100%;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
2022-07-28 21:24:28 +08:00
|
|
|
|
|
|
|
.container {
|
|
|
|
display: grid;
|
|
|
|
grid-template-rows: 1fr 50px;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
|
2022-07-29 14:44:23 +08:00
|
|
|
.iframe-container,
|
2022-07-28 21:24:28 +08:00
|
|
|
iframe {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
#float-container.bt {
|
|
|
|
bottom: 0;
|
|
|
|
right: 0;
|
|
|
|
left: 0;
|
|
|
|
height: 100%;
|
|
|
|
background-color: #fdfdfd;
|
|
|
|
box-shadow: 0 -2px 10px 0 rgb(0 0 0 / 10%);
|
|
|
|
display: grid;
|
2022-07-29 16:51:28 +08:00
|
|
|
/* grid-template-columns: repeat(3, 1fr); */
|
2022-07-28 21:24:28 +08:00
|
|
|
place-items: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
#float-container.bt .navbar-item {
|
|
|
|
text-align: center;
|
|
|
|
cursor: pointer;
|
2022-07-29 14:08:23 +08:00
|
|
|
width: 80px;
|
|
|
|
user-select: none;
|
2022-07-28 21:24:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#float-container.bt .navbar-item .navbar-image {
|
|
|
|
width: 22px;
|
|
|
|
height: 22px;
|
|
|
|
filter: grayscale(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#float-container.bt .navbar-item .navbar-title {
|
|
|
|
font-size: 11px;
|
|
|
|
color: #666;
|
|
|
|
margin-top: -3px;
|
|
|
|
}
|
|
|
|
|
|
|
|
#float-container.bt .navbar-item.active .navbar-image {
|
|
|
|
filter: initial;
|
|
|
|
}
|
2022-07-27 00:48:24 +08:00
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
2022-07-28 21:24:28 +08:00
|
|
|
<div class="container">
|
2022-07-29 14:44:23 +08:00
|
|
|
<div id="iframe-container">
|
2022-07-29 17:37:56 +08:00
|
|
|
<!-- <iframe id="main-iframe" src="html/weibo.html" frameborder="0"></iframe> -->
|
2022-07-29 14:44:23 +08:00
|
|
|
</div>
|
2022-07-29 16:51:28 +08:00
|
|
|
<div id="float-container" class="bt">
|
|
|
|
<!-- <div class="navbar-item" targetPage="weibo_hotband">
|
2022-07-28 21:24:28 +08:00
|
|
|
<img class="navbar-image" src="./html/assets/image/weibo.svg" />
|
2022-07-29 16:31:06 +08:00
|
|
|
<p class="navbar-title">微博热搜</p>
|
2022-07-29 16:51:28 +08:00
|
|
|
</div> -->
|
2022-07-28 21:24:28 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<script>
|
2022-07-29 16:51:28 +08:00
|
|
|
let pages = {
|
|
|
|
'weibo_hotband': {
|
|
|
|
title: '微博热搜',
|
|
|
|
// url: 'html/weibo_hotband.html',
|
|
|
|
icon: './html/assets/image/weibo.svg',
|
|
|
|
icon_scale: 1,
|
|
|
|
},
|
|
|
|
'bilibili_hotband': {
|
|
|
|
title: 'B站热搜',
|
|
|
|
// url: 'html/bilibili_hotband.html',
|
|
|
|
icon: './html/assets/image/bilibili.svg',
|
|
|
|
icon_scale: 0.87,
|
|
|
|
},
|
2022-07-29 17:37:56 +08:00
|
|
|
'bilibili_rank': {
|
|
|
|
title: 'B站排行',
|
|
|
|
// url: 'html/bilibili_rank.html',
|
|
|
|
icon: './html/assets/image/icon_rank.png',
|
2022-07-29 20:33:57 +08:00
|
|
|
icon_scale: 0.87,
|
2022-07-29 17:37:56 +08:00
|
|
|
},
|
2022-07-29 16:51:28 +08:00
|
|
|
};
|
|
|
|
// 渲染导航栏
|
|
|
|
for (let key in pages) {
|
|
|
|
let page = pages[key];
|
|
|
|
let navbarItem = document.createElement('div');
|
|
|
|
navbarItem.className = 'navbar-item';
|
|
|
|
navbarItem.setAttribute('targetPage', key);
|
|
|
|
navbarItem.innerHTML = `
|
|
|
|
<img class="navbar-image" src="${page.icon}" ${page.icon_scale != 1 ? `style="transform: scale(${page.icon_scale});"` : ''} />
|
|
|
|
<p class="navbar-title"> ${page.title}</p>
|
|
|
|
`;
|
|
|
|
document.getElementById('float-container').style.gridTemplateColumns = `repeat(${Object.keys(pages).length}, 1fr)`;
|
|
|
|
document.getElementById('float-container').appendChild(navbarItem);
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<script>
|
2022-07-28 21:24:28 +08:00
|
|
|
let navbarItems = document.querySelectorAll('.navbar-item');
|
2022-07-29 14:44:23 +08:00
|
|
|
let iframeContainer = document.querySelector('#iframe-container');
|
2022-07-29 17:37:56 +08:00
|
|
|
let iframe = document.querySelector('#main-iframe');
|
2022-07-28 21:24:28 +08:00
|
|
|
navbarItems.forEach(item => {
|
|
|
|
item.addEventListener('click', () => {
|
2022-07-29 14:44:23 +08:00
|
|
|
// 已选中项再次点击,不执行操作
|
2022-07-29 16:51:28 +08:00
|
|
|
if (item.classList.contains('active')) return;
|
2022-07-29 14:44:23 +08:00
|
|
|
|
2022-07-28 21:24:28 +08:00
|
|
|
navbarItems.forEach(item => {
|
|
|
|
item.classList.remove('active');
|
|
|
|
});
|
|
|
|
item.classList.add('active');
|
2022-07-29 14:44:23 +08:00
|
|
|
|
|
|
|
let target = item.getAttribute('targetPage');
|
|
|
|
switchPage(target, true);
|
2022-07-28 21:24:28 +08:00
|
|
|
});
|
|
|
|
});
|
2022-07-29 14:44:23 +08:00
|
|
|
|
|
|
|
// 切换页面
|
|
|
|
// 传入参数:目标页面,是否更新网址
|
|
|
|
function switchPage(target, pushState) {
|
|
|
|
let url = `html/${target}.html`;
|
|
|
|
if (pushState) {
|
|
|
|
// 更新url但不刷新页面
|
|
|
|
history.pushState(null, null, `./index.html?target=${target}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
// iframe 进入新页面
|
|
|
|
if (iframe)
|
|
|
|
iframe.remove();
|
|
|
|
iframe = document.createElement('iframe');
|
2022-07-29 17:37:56 +08:00
|
|
|
iframe.id = "main-iframe";
|
2022-07-29 14:44:23 +08:00
|
|
|
iframe.src = url;
|
|
|
|
iframe.setAttribute('frameborder', '0');
|
|
|
|
iframeContainer.appendChild(iframe);
|
2022-07-29 17:37:56 +08:00
|
|
|
|
|
|
|
iframe.addEventListener('load', function (event) {
|
|
|
|
console.log(event);
|
|
|
|
document.title = document.getElementById("main-iframe").contentWindow.document.title + " | 热搜榜单"
|
|
|
|
}, true);
|
2022-07-29 14:44:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 根据 URL 参数切换页面
|
|
|
|
function locationToPageByUrlParam() {
|
|
|
|
// 获取 url 中的 target 参数
|
|
|
|
let url = new URL(window.location.href);
|
|
|
|
let target = url.searchParams.get('target');
|
2022-07-29 16:51:28 +08:00
|
|
|
if (!Object.keys(pages).includes(target)) {
|
|
|
|
target = 'weibo_hotband';
|
2022-07-29 14:44:23 +08:00
|
|
|
history.replaceState(null, null, `./index.html?target=${target}`);
|
|
|
|
}
|
|
|
|
// 切换页面
|
|
|
|
switchPage(target, false);
|
|
|
|
// 更新下方导航栏选中状态
|
2022-07-29 17:48:54 +08:00
|
|
|
let oldActive = document.querySelector('.active')
|
|
|
|
if (oldActive) oldActive.classList.remove('active');
|
2022-07-29 14:44:23 +08:00
|
|
|
navbarItems.forEach(item => {
|
|
|
|
if (item.getAttribute('targetPage') === target) {
|
|
|
|
item.classList.add('active');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener("popstate", function (e) {
|
|
|
|
console.log("浏览器返回事件", e);
|
|
|
|
locationToPageByUrlParam();
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
locationToPageByUrlParam();
|
2022-07-28 21:24:28 +08:00
|
|
|
</script>
|
2022-07-27 00:48:24 +08:00
|
|
|
</body>
|
|
|
|
|
|
|
|
</html>
|