mirror of
https://github.com/tuna/mirror-web.git
synced 2025-12-25 20:32:46 +00:00
remove scripts for index page
This commit is contained in:
parent
3b77340a60
commit
c459c1cad2
|
|
@ -1,201 +0,0 @@
|
|||
---
|
||||
---
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
var global_options = {% include options.json %};
|
||||
var label_map = global_options.options.label_map;
|
||||
var help_url = {};
|
||||
global_options.helps.forEach((h) => help_url[h.mirrorid] = h.url);
|
||||
var new_mirrors = {};
|
||||
global_options.options.new_mirrors.forEach((m) => new_mirrors[m] = true);
|
||||
var unlisted = global_options.options.unlisted_mirrors;
|
||||
var options = {};
|
||||
global_options.options.force_redirect_help_mirrors.forEach((m) => options[m] = {'url': "/help/" + m + "/"})
|
||||
var descriptions = {};
|
||||
global_options.options.mirror_desc.forEach((m) => descriptions[m.name] = m.desc);
|
||||
|
||||
const vmMirList = new Vue({
|
||||
el: "#mirror-list",
|
||||
data: {
|
||||
test: "hello",
|
||||
mirrorList: [],
|
||||
filter: "",
|
||||
rawMirrorList: [],
|
||||
dateTooltip: localStorage.getItem('DateTooltip') !== 'false',
|
||||
haveSearchBox: false,
|
||||
},
|
||||
created() {
|
||||
this.refreshMirrorList();
|
||||
},
|
||||
mounted() {
|
||||
if (this.$refs.search){
|
||||
this.haveSearchBox = true;
|
||||
}
|
||||
if (this.haveSearchBox){
|
||||
window.addEventListener("keypress", this.onKeyPress);
|
||||
}
|
||||
window.addEventListener("visibilitychange", this.onVisibilityChange);
|
||||
},
|
||||
beforeDestroy() {
|
||||
if (this.haveSearchBox){
|
||||
window.removeEventListener("keypress", this.onKeyPress);
|
||||
}
|
||||
},
|
||||
updated() {
|
||||
Array.from(document.getElementsByClassName('mirror-item-label')).map((el) => {
|
||||
new bootstrap.Popover(el);
|
||||
});
|
||||
},
|
||||
computed: {
|
||||
nowBrowsingMirror: function() {
|
||||
var mirrorName = location.pathname.split('/')[1];
|
||||
if (!mirrorName){
|
||||
return false;
|
||||
}
|
||||
mirrorName = mirrorName.toLowerCase();
|
||||
const result = this.mirrorList.filter((m) => {
|
||||
return m.name.toLowerCase() === mirrorName;
|
||||
})[0];
|
||||
if (!result){
|
||||
return false;
|
||||
}
|
||||
return result;
|
||||
},
|
||||
filteredMirrorList: function() {
|
||||
var filter = this.filter.toLowerCase();
|
||||
return this.mirrorList.filter((m) => {
|
||||
return m.is_master && m.name.toLowerCase().indexOf(filter) !== -1;
|
||||
});
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
getURL(mir) {
|
||||
if (mir.url !== undefined) {
|
||||
return mir.url
|
||||
}
|
||||
return `/${mir.name}/`
|
||||
},
|
||||
refreshMirrorList() {
|
||||
// do nothing if the tab is not visible
|
||||
if (document.hidden === true) {
|
||||
return;
|
||||
}
|
||||
var self = this;
|
||||
fetch("/static/tunasync.json").then((res)=>res.json()).then((status_data) => {
|
||||
const unlisted_mir = unlisted.map(d => processMirrorItem(d))
|
||||
status_data = status_data.map(d => processMirrorItem(d));
|
||||
var mir_data = unlisted_mir.concat(status_data);
|
||||
mir_data = processLinkItem(mir_data);
|
||||
status_data = sortAndUniqMirrors(status_data);
|
||||
mir_data = sortAndUniqMirrors(mir_data).filter(d => !(d.status == "disabled"));
|
||||
self.mirrorList = mir_data;
|
||||
self.rawMirrorList = status_data;
|
||||
self.refreshTimer = setTimeout(() => {self.refreshMirrorList()}, 10000);
|
||||
});
|
||||
},
|
||||
onKeyPress(event) {
|
||||
if (event.key === '/' && document.activeElement !== this.$refs.search) {
|
||||
event.preventDefault();
|
||||
this.$refs.search.focus();
|
||||
}
|
||||
},
|
||||
onVisibilityChange() {
|
||||
// disable the timer anyway
|
||||
clearTimeout(this.refreshTimer);
|
||||
if (document.visibilityState === 'visible') {
|
||||
this.refreshMirrorList();
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
var stringifyTime = (ts) => {
|
||||
const date = new Date(ts * 1000);
|
||||
var str = "";
|
||||
var ago = "";
|
||||
if (date.getFullYear() > 2000) {
|
||||
str = `${('000'+date.getFullYear()).substr(-4)}-${('0'+(date.getMonth()+1)).substr(-2)}-${('0'+date.getDate()).substr(-2)}` +
|
||||
` ${('0'+date.getHours()).substr(-2)}:${('0'+date.getMinutes()).substr(-2)}`;
|
||||
ago = timeago.format(date);
|
||||
} else {
|
||||
str = "0000-00-00 00:00";
|
||||
ago = "Never";
|
||||
}
|
||||
return [str, ago];
|
||||
}
|
||||
|
||||
var sortAndUniqMirrors = (mirs) => {
|
||||
mirs.sort((a, b) => { return a.name < b.name ? -1: 1 });
|
||||
return mirs.reduce((acc, cur)=>{
|
||||
if(acc.length > 1 && acc[acc.length - 1].name == cur.name){
|
||||
if(acc[acc.length - 1].last_update_ts && cur.last_update_ts){
|
||||
if(acc[acc.length - 1].last_update_ts < cur.last_update_ts){
|
||||
acc[acc.length - 1] = cur;
|
||||
}
|
||||
} else if(cur.last_update_ts){
|
||||
acc[acc.length - 1] = cur;
|
||||
}
|
||||
}else{
|
||||
acc.push(cur);
|
||||
}
|
||||
return acc;
|
||||
}, []);
|
||||
}
|
||||
|
||||
const processLinkItem = (mirrors) => {
|
||||
var processed = [];
|
||||
for (let d of mirrors) {
|
||||
if (d.link_to === undefined) {
|
||||
processed.push(d);
|
||||
continue;
|
||||
}
|
||||
for (const target of mirrors) {
|
||||
if (d.link_to === target.name) {
|
||||
d.status = target.status;
|
||||
d.label = target.label;
|
||||
d.upstream = target.upstream;
|
||||
d.show_status = target.show_status;
|
||||
d.last_update = target.last_update;
|
||||
d.last_update_ago = target.last_update_ago;
|
||||
d.last_ended = target.last_ended;
|
||||
d.last_ended_ago = target.last_ended_ago;
|
||||
d.last_schedule = target.last_schedule;
|
||||
d.last_schedule_ago = target.last_schedule_ago;
|
||||
processed.push(d);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return processed;
|
||||
};
|
||||
|
||||
const processMirrorItem = (d) => {
|
||||
if (options[d.name] != undefined ) {
|
||||
for( const key of Object.keys(d) ) {
|
||||
if (options[d.name].hasOwnProperty(key)) {
|
||||
d[key] = options[d.name][key];
|
||||
}
|
||||
}
|
||||
}
|
||||
d.help_url = help_url[d.name];
|
||||
d.is_new = Boolean(new_mirrors[d.name]);
|
||||
d.description = descriptions[d.name];
|
||||
d.github_release = d.url && d.url.startsWith('/github-release/');
|
||||
if (d.is_master === undefined) {
|
||||
d.is_master = true;
|
||||
}
|
||||
if (d.link_to !== undefined) {
|
||||
return d;
|
||||
}
|
||||
d.label = label_map[d.status];
|
||||
d.show_status = (d.status != "success");
|
||||
// Strip the second component of last_update
|
||||
[d.last_update, d.last_update_ago] = stringifyTime(d.last_update_ts);
|
||||
[d.last_ended, d.last_ended_ago] = stringifyTime(d.last_ended_ts);
|
||||
[d.last_started, d.last_started_ago] = stringifyTime(d.last_started_ts);
|
||||
[d.next_schedule, d.next_schedule_ago] = stringifyTime(d.next_schedule_ts);
|
||||
return d;
|
||||
};
|
||||
});
|
||||
|
||||
// vim: ts=2 sts=2 sw=2 noexpandtab
|
||||
|
|
@ -1 +0,0 @@
|
|||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).timeago={})}(this,function(e){"use strict";var r=["second","minute","hour","day","week","month","year"];var a=["秒","分钟","小时","天","周","个月","年"];function t(e,t){n[e]=t}function i(e){return n[e]||n.en_US}var n={},c=[60,60,24,7,365/7/12,12];function o(e){return e instanceof Date?e:!isNaN(e)||/^\d+$/.test(e)?new Date(parseInt(e)):(e=(e||"").trim().replace(/\.\d+/,"").replace(/-/,"/").replace(/-/,"/").replace(/(\d)T(\d)/,"$1 $2").replace(/Z/," UTC").replace(/([+-]\d\d):?(\d\d)/," $1$2"),new Date(e))}function f(e,t){for(var n=e<0?1:0,r=e=Math.abs(e),a=0;e>=c[a]&&a<c.length;a++)e/=c[a];return(0===(a*=2)?9:1)<(e=~~e)&&(a+=1),t(e,a,r)[n].replace("%s",e)}function d(e,t){return(+(t=t?o(t):new Date)-+o(e))/1e3}var s="timeago-id";function l(e){return parseInt(e.getAttribute(s))}var p={},v=function(e){clearTimeout(e),delete p[e]};function h(e,t,n,r){v(l(e));var a=r.relativeDate,i=r.minInterval,o=d(t,a);e.innerText=f(o,n);var u=setTimeout(function(){h(e,t,n,r)},Math.min(1e3*Math.max(function(e){for(var t=1,n=0,r=Math.abs(e);e>=c[n]&&n<c.length;n++)e/=c[n],t*=c[n];return r=(r%=t)?t-r:t,Math.ceil(r)}(o),i||1),2147483647));p[u]=0,function(e,t){e.setAttribute(s,t)}(e,u)}t("en_US",function(e,t){if(0===t)return["just now","right now"];var n=r[~~(t/2)];return 1<e&&(n+="s"),[e+" "+n+" ago","in "+e+" "+n]}),t("zh_CN",function(e,t){if(0===t)return["刚刚","片刻后"];var n=a[~~(t/2)];return[e+" "+n+"前",e+" "+n+"后"]}),e.cancel=function(e){e?v(l(e)):Object.keys(p).forEach(v)},e.format=function(e,t,n){return f(d(e,n&&n.relativeDate),i(t))},e.register=t,e.render=function(e,t,n){var r=e.length?e:[e];return r.forEach(function(e){h(e,function(e){return e.getAttribute("datetime")}(e),i(t),n||{})}),r},Object.defineProperty(e,"__esModule",{value:!0})});
|
||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue