本WIKI由旅行者酒馆于2020年03月14日申请开通,内容按CC BY-NC-SA 4.0协议提供,编辑权限开放。感谢 大猫雷恩 对WIKI设计支持,期待更多能人异士加入原神WIKI。
免责声明 • 反馈留言 • 交流群:1018709157
原神WIKI五周年啦!
bugfix250107.1

全站通知:

Widget:Datatext

来自原神WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

<script> var DataText = function(){ var dataset = {}; var paraser = function() { $(".datatext").each(function(){ var name = $(this).attr("data-name"), informat = $(this).attr("data-input-format"), outformat = $(this).attr("data-output-format"); if(!name || !informat || !outformat) return true; var temp = from[informat](this); var thead = $(this).attr("data-column"); if(thead) temp.unshift(thead.split(",")); if(informat.indexOf("json") === 0) return dataset[name] = temp.data || temp; dataset[name] = to[outformat](temp.data || temp); }); }; var from = { "jsonparse": function(obj) { return JSON.parse($(obj).text()); }, "jsonstr": function(obj) { return (new Function('return ' + '{' + $(obj).text() + '}'))(); }, "wikitext-table": function(obj) { var table = $(obj).text().replace(/\r|\t/g,"").split("\n|-\n"); window.temp = table[0]; $.each(table, function(i, row){ table[i] = row = row.replace(/\n/g, "").replace(/^\|/,"").split("||"); $.each(row, function(j, v){table[i][j] = $.trim(v)}); }) return table; } }; var to = { json: function(table) { var key = table.splice(0,1)[0]; var json = []; $.each(table, function(i, row){ if(!row || row === "") return true; if(row.length === 1 && row[0] === "") return true; var obj = {}; $.each(row, function(j, val){ obj[key[j]] = val; }); json.push(obj); }); return json; } }; var get = function(key){ return dataset[key]; } paraser(); return { get: get } } </script>