-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelloWorld.user.js
69 lines (57 loc) · 1.91 KB
/
HelloWorld.user.js
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
// ==UserScript==
// @name HelloWorld
// @namespace hw
// @description first script
// @include http://bbs.nju.edu.cn/blogdoc?userid=snc
// @include http://bbs.nju.edu.cn/blogdoc?userid=snc*
// @version 1
// ==/UserScript==
//alert("hello");
/*var count = 1;
var File1 = document.getElementById("file1");
var div = document.createElement("div");
var countTxt = document.createTextNode("Text:"+count);
var inputTxt = document.createElement("input");
*/
// version 1, add an input in the page
/*var fonts = document.getElementsByTagName('font');
if (fonts.length) {
var firstFont = fonts[0];
var input = document.createElement('input');
input.type = 'text';
firstFont.parentNode.insertBefore(input, firstFont.nextSibling);
} */
function putInput() {
GM_log("run here");
//var input = document.createElement('input');
//var btn = document.createElement('button');
var myTbl = document.createElement('table');
myTbl.innerHTML = '<table><tr><td></td></tr><tr><td></td></tr>';
var textField = document.createElement('input');
textField.type = 'text';
var button = document.createElement('input');
button.type = 'button';
button.value = 'OK';
/*button.onclick = function() {
alert("hello");
};*/
button.onclick=myHandleClick;
myTbl.firstChild.firstChild.appendChild(textField);
myTbl.lastChild.firstChild.appendChild(button);
var br = document.createElement('br');
var tbls = document.getElementsByTagName('table');
var tds = tbls[0].getElementsByTagName('td'); //2 columns in the table. We get the 1st
var td = tds[0];
var tbl = td.getElementsByTagName('table')[1]; //2 tables in this column. we get the second.
tbl.parentNode.insertBefore(br, tbl.nextSibling);
br.parentNode.insertBefore(myTbl, br.nextSibling);
}
function myHandleClick() {
// alert("hello!!");
window.open("http://www.google.com.hk");
}
function main() {
putInput();
// document.addEventListener('click', handleClick);
}
main();