-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
101 lines (92 loc) · 3.07 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>url参数解表格</title>
<!-- <link rel="stylesheet" href="http://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css"> -->
<link rel="stylesheet" href="https://getbootstrap.com/dist/css/bootstrap.min.css">
<style>
td {
max-width: 100px;
overflow: hidden;
white-space: nowrap;
}
</style>
</head>
<body>
<h4>URL链接批量参数提取,转表格工具</h4>
<p>在框内输入URL链接(一行一个URL)</p>
<textarea id="urls" name="urls" cols="200" rows="10"></textarea>
<button>确定</button>
<table id="table" class="table table-bordered table-responsive"></table>
<script src="http://code.jquery.com/jquery-1.12.4.js"></script>
<script src="http://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
<script>
var tabs = ['page_id', 'oper_id', 'oper_obj_id', 'oper_obj_type', 'ret_id'];
var dataTable;
$('textarea').on('change', handler);
function handler() {
var urls = $('#urls').val().split('\n');
if (!urls.length) return;
var table = [];
$.each(urls, function(index, url) {
var search = url.split('?')[1];
if (!search) return;
var params = search.split('&');
table[index] = {};
$.each(params, function(i, str) {
if (!str) return;
var s = str.split('=');
table[index][s[0]] = s[1];
});
});
// buildTable(table);
buildTableData(table);
}
/*
function buildTable(data) {
var tbody = $.map(data, function(line) {
var result = [];
$.each(line, function(key, val) {
var tdIndex = tabs.indexOf(key);
if (tdIndex > -1) {
result[tdIndex] = val;
} else {
tabs.push(key);
result[tabs.length-1] = val;
}
});
return '<tr>' + $.map(result, function(val) {
return '<td>' + (typeof val === 'undefined' ? '' : val) + '</td>';
}).join('') + '</tr>';
}).join('');
var thead = $.map(tabs, function(tab) {
return '<td>' + tab + '</td>';
}).join('');
$('table').html('<thead><tr>' + thead + '</tr></thead><tbody>' + tbody + '</tbody>').DataTable();
}
*/
function buildTableData(data) {
$.map(data, function(line) {
$.each(line, function(key, val) {
if (tabs.indexOf(key) === -1) {
tabs.push(key);
}
});
});
var params = {
data: data,
columns: $.map(tabs, function(tab) {
return {
data: tab,
title: tab,
defaultContent: ''
};
})
};
dataTable && dataTable.destroy();
dataTable = $('table').empty().DataTable(params);
}
</script>
</body>
</html>