Skip to content

Instantly share code, notes, and snippets.

@zhoukekestar
Last active February 8, 2018 11:30
Show Gist options
  • Save zhoukekestar/f490276bf2d66e6c5e4c4e76e9eecdb8 to your computer and use it in GitHub Desktop.
Save zhoukekestar/f490276bf2d66e6c5e4c4e76e9eecdb8 to your computer and use it in GitHub Desktop.
inject-code
const injectCSS = () => {
var style = document.createElement('style');
style.innerHTML = `
table.public_table.table_column td > button {
position: absolute;
left: 0;
background: rgba(0, 0, 0, 0.99);
border: none;
color: #fff;
font-size: 12px;
opacity: .1;
border-radius: 3px;
cursor: pointer;
}
table.public_table.table_column td > button:hover {
opacity: 1;
}
.chart-dialog {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: rgba(255, 255, 255, 0.92);
z-index: 999;
padding: 60px 40px;
box-sizing: border-box;
display: none;
}
.chart-dialog.open {
display: block;
}
`;
document.body.appendChild(style);
}
const injectComponent = () => {
// import chart-js
const link = document.createElement('link');
link.rel = 'import';
link.href = 'https://zhoukekestar.github.io/webcomponents/components/chart-js/chart-js.v2.html';
document.body.appendChild(link);
}
if (location.host == 'data.stats.gov.cn') {
injectCSS();
injectComponent();
// dialog & chartjs refs
const chartDialog = document.createElement('div');
chartDialog.classList.add('chart-dialog');
chartDialog.onclick = function() {
this.classList.remove('open');
}
document.body.appendChild(chartDialog);
const showChart = (e) => {
chartDialog.classList.add('open');
chartDialog.innerHTML = `<chart-js></chart-js>`;
const chartjs = chartDialog.querySelector('chart-js');
console.log(e);
const tr = e.target.closest('tr');
const table = e.target.closest('table');
const labels = Array.from(table.querySelectorAll('thead th + th')).map(th => th.textContent);
const data = Array.from(tr.querySelectorAll('td + td')).map(td => +td.innerHTML);
chartjs.singleLine(data.map((td, index) => {
return {
name: labels[index],
value: td,
}
}).reverse());
}
const init = () => {
const mainTable = document.querySelector('table.public_table.table_column');
Array.from(mainTable.querySelectorAll('tbody tr')).map(tr => {
const td = tr.querySelector('td:first-child');
if (!td.querySelector('button')) {
const btn = document.createElement('button');
btn.innerHTML = '显示数据';
btn.onclick = showChart;
td.appendChild(btn);
}
});
}
setInterval(() => {
init();
}, 1000);
}
@zhoukekestar
Copy link
Author

zhoukekestar commented Feb 1, 2018

[{"name":"base-common","code":"window.injectBtn = (url, text, func) => {\n if (location.href.indexOf(url) !== -1) {\n var btn = document.createElement('button')\n btn.innerHTML = text;\n btn.setAttribute('style', \n position: fixed;\n right: 50px;\n top: 50px;\n z-index: 999999;\n );\n btn.onclick = func\n document.body.appendChild(btn)\n }\n}","active":1,"hidden":0},{"name":"开启页面","code":"const a = document.createElement('a')\na.target = '_blank';\n\n[\n 'http://tech.qq.com/',\n\t'http://news.baidu.com/',\n 'http://weibo.com/u/3514877350/home?topnav=1&wvr=5',\n 'http://www.tuicool.com/a/',\n 'https://github.com/trending',\n 'http://www.kekenet.com/read/news/',\n].forEach(url => {\n a.href = url;\n\ta.click()\n});","active":0,"hidden":0},{"name":"debugMode","code":"location.replace(location.href + (/\?/.test(location.href) ? '&' : '?') + 'debugMode=1')","active":0,"hidden":0},{"name":"roc 页面灰度","code":"location.replace(location.href + (/\?/.test(location.href) ? '&' : '?') + 'setGray=true')","active":0,"hidden":0},{"name":"账号登录","code":"var __name = 'b测试账号005'; var __password = '';\nif (location.href.indexOf('login.m.taobao.com/login.htm') > 0) {\n document.querySelector('input[name=TPL_username]').value = __name;\n document.querySelector('input[type=password]').value = __password;\n document.querySelector('#submit-btn').disabled = false;\n}\n\nif (location.href.indexOf('login.1688.com/member/signin.htm') > 0) {\n location.href = document.querySelector('iframe').src;\n}\n\nif (location.href.indexOf('login.taobao.com/member/login.jhtml') > 0) {\n document.querySelector('input[name=TPL_username]').value = __name;\n document.querySelector('input[type=password]').value = __password;\n}","active":1,"hidden":0},{"name":"mtop 切换为测试页面","code":"injectBtn('http://max.m.taobao.com/mtop/managerapi/view', '切换为测试页', () => {\n\tlocation.href = location.href.replace('managerapi/view?api', 'testmodule/apitest?apiName').replace('&v=', '&apiV=') \n});","active":1,"hidden":0},{"name":"IP -> loca.1688.com","code":"location.href = location.href.replace(/\d+\.\d+.\d+.\d+/, 'local.1688.com') + '&wapa' + '&findLoginId=b测试账号005&buyerLoginId=b测试账号005';","active":0,"hidden":0},{"name":"OmniPlan Format","code":" // remove time\n Array.from(document.querySelectorAll('td')).map(td => {\n // console.log(td);\n td.innerHTML = td.innerHTML.replace(/,\ \d\d:\d\d/, '');\n })\n\n function removeColum(title) {\n const index = Array.from(document.querySelectorAll('th')).findIndex(th => th.innerHTML === title);\n Array.from(document.querySelectorAll(tr td:nth-child(${index + 1}), tr th:nth-child(${index + 1}))).map(item => item.remove())\n }\n ['Total Cost', 'Constraint Start', 'End Variance', 'Start Variance', 'Constraint End'].map(title => removeColum(title))\n\n const assignedIndex = Array.from(document.querySelectorAll('th')).findIndex(th => th.innerHTML === 'Assigned');\n Array.from(document.querySelectorAll('tr')).map(tr => {\n let assigned = tr.querySelector(td:nth-child(${assignedIndex + 1}));\n assigned = assigned && assigned.innerHTML || '';\n if (assigned && !/pipe/i.test(assigned)) {\n tr.style.color = '#e2e2e2';\n }\n })","active":0,"hidden":0},{"name":"多 PI 切换","code":"\nif (location.href.indexOf('wdc.alibaba-inc.com/roc/page/edit.htm') > -1) {\n var header = document.querySelector('.page-edit-header-title')\n var button = document.createElement('button');\n button.innerHTML = '切换到 PiBase';\n header.appendChild(button)\n button.className = 'ant-btn ant-btn-ghost btn-ghost-roc';\n button.onclick = function() {\n jQuery.getJSON(https://wdc.alibaba-inc.com/roc/page/updatePagePiType.jsonp?pageId=${location.search.match(/pageId=([^&]*)/)[1]}&piType=pi2, function(data){\n console.log(data);\n alert('ok, please re-release page');\n });\n }\n// pi 预发\n// http://diamond.alibaba-inc.com/diamond-ops/static/pages/config-edit/index.html?serverId=pre&dataId=com.alibaba.mobile.roc.rax.Config&group=com.alibaba.mobile.group\n \n \n}\n\n","active":1,"hidden":0},{"name":"deps.json 分析","code":"var cdn = [\n {\n "cdnurl": "http://g.alicdn.com/code/npm/rax-components/0.4.9/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/universal-panresponder/0.4.9/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/universal-emitter/1.0.5/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/universal-retcodelog/0.0.1/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/universal-toast/0.4.9/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-theme/0.2.1/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/rax/0.4.9/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/universal-env/0.4.9/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-smartapp/1.0.5/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/universal-transition/0.1.8/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/universal-device/0.0.1/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/universal-transition/1.0.7/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/universal-toast/1.0.3/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/universal-panresponder/1.0.3/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/universal-env/1.1.6/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/rax-components/1.2.2/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/universal-dimensions/1.1.5/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/universal-spm/1.1.1/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-location/1.0.2/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/universal-windvane/1.0.4/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-toast/1.0.1/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/rax-grid/1.0.7/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-env/1.0.2/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/rax-icon/1.0.4/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-dimensions/1.0.0/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-windvane/1.0.1/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/rax-swipe/1.0.5/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/rax-feedback-page/0.0.2/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/universal-cox-tracker/0.0.4/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-tracelog/1.0.4/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox/1.0.4/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-dialog/1.0.0/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-device/1.0.0/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-global-event/1.0.0/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-rax-slider/0.0.1/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-rax-tabheader/0.0.2/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-webview/1.0.0/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-module/1.0.1/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-user/1.0.2/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-link/1.0.5/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-window/1.0.3/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-logger/1.0.0/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-image/1.0.10/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-mtop/1.0.6/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-components/1.0.3/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/roc-mod-wg-newer-entry/1.0.5/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-tabbar/2.0.7/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-sticky/1.1.5/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-banner-maparea/2.0.3/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-sidebutton/2.0.8/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-slider/2.0.8/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-wg-login-popup/1.0.5/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-view-more/1.0.1/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-util/1.0.3/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-title/2.1.5/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-3xtheme-entry/2.0.3/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-wg-base/1.1.12/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-list/2.0.17/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-page/1.4.9/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-tabheader/2.0.14/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-blank/2.0.2/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-wgmarket-choiceness/2.0.2/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-wgmarket-offer-item/2.1.9/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-pi-roc/1.4.5/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-wgmarket-secondtabheader/2.0.1/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-demo-mounter/2.1.2/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-wgmarket-recom/1.0.2/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-wgmarket-category/1.0.2/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-wgmarket-header-config/1.0.2/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/cox-telecast/2.0.5/index.cmd.js"\n },\n {\n "cdnurl": "http://g.alicdn.com/code/npm/@ali/rax-cox-pi/0.0.5/index.cmd.js"\n },\n // {\n // "cdnurl": "http://g.alicdn.com/code/npm/rax-redux/0.5.0/index.cmd.js"\n // },\n]\nvar name2version = {};\nvar had = cdn.map(item => {\n let name = item.cdnurl.match(/npm\/([^\\d])/)[1];\n let version = item.cdnurl.match(/\d\.\d*\.\d*/)[0];\n name = name.substring(0, name.length - 1);\n name2version[name] = version;\n return name;\n});\n\nvar json = JSON.parse(document.querySelector('pre').innerHTML);\njson = Object.keys(json).map(item => {\n let name = item.match(/npm\/([^\\d])/)[1];\n let version = item.match(/\d\.\d*\.\d*/)[0];\n name = name.substring(0, name.length - 1);\n name2version[name] = version;\n return name;\n})\njson = new Set(json);\n\nhad.map(name => {\n json.delete(name);\n})\n\nvar result = Array.from(json).map(name => {\n return {\n "dependencies": [\n \n ],\n "module": name,\n "version": name2version[name],\n "wapDependencies": [\n \n ]\n }\n})\n\nconsole.log(JSON.stringify(result, null, 2))","active":0,"hidden":0},{"name":"隐藏 app 导航栏","code":"location.href += '&existtitle=1';","active":0,"hidden":0},{"name":"just index.weex.js","code":"var justforweexjs = function() {\n var bundles = Array.from(document.querySelectorAll('.m-rax-page-item-actions .m-rax-page-item-icon-link:last-child'));\n\n bundles.map(span => {\n var a = span.querySelector('a');\n var name = a.href.match(/([^\\/]*)\.html/)[1];\n var url = new URL(a.href);\n\n \n var newLink = document.createElement('a');\n newLink.href = ${url.origin}/build/pages/${name}/index.weex.js;\n newLink.innerHTML = 'index.weex.js';\n newLink.target = '_blank';\n span.appendChild(newLink);\n console.log(newLink)\n })\n}\nif (/127.0.0.1\/project\/detail/.test(location.href)) {\n setTimeout(justforweexjs, 2000)\n}\n","active":1,"hidden":0}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment