File tree Expand file tree Collapse file tree 5 files changed +56
-36
lines changed
Expand file tree Collapse file tree 5 files changed +56
-36
lines changed Original file line number Diff line number Diff line change 11document . body . style . border = "1px solid red" ;
22
3- let tables = document . querySelectorAll ( "table" ) ;
3+ function getTables ( ) {
4+ return document . querySelectorAll ( "table" ) ;
5+ }
6+ let tables = getTables ( ) ;
47console . log ( "tables" , tables ) ;
5- let tables2 = Array . from ( tables ) . map ( ( table ) => {
6- return table . classList . add ( "table-sort" ) ;
7- } ) ;
8-
9-
10-
8+ function addTableSortClass ( ) {
9+ let tablesWithTableSortClass = Array . from ( tables ) . map ( ( table ) => {
10+ return table . classList . add ( "table-sort" ) ;
11+ } ) ;
12+ return tablesWithTableSortClass ;
13+ }
14+ addTableSortClass ( ) ;
Original file line number Diff line number Diff line change 1- // let tables = document.querySelectorAll("table").querySelectorAll("th");
2- // console.log("tables3", tables );
3- let headers = document . querySelectorAll ( "table th" ) ;
4- console . log ( "tables3 " , headers ) ;
5-
6- let headerText = headers . map ( ( header ) => header . innerHTML )
7- console . log ( headerText )
1+ function getTableHeaders ( ) {
2+ let headers = document . querySelectorAll ( "table th" ) ;
3+ let headerNames = Array . from ( headers ) . map ( ( header ) => header . innerText ) ;
4+ console . log ( "test " , headerNames ) ;
5+ return headerNames ;
6+ }
7+ getTableHeaders ( ) ;
Original file line number Diff line number Diff line change 11{
22 "manifest_version" : 2 ,
3+ "author" :" Lee Wannacott" ,
34 "name" : " table-sort-js" ,
45 "version" : " 0.0" ,
56 "description" : " Makes tables sortable using https://github.com/LeeWannacott/table-sort-js" ,
6-
77 "icons" :
88 { "48" : " icons/t.png" }
99 ,
10-
10+ "browser_action" : {
11+ "default_icon" : " ./icons/t.png" ,
12+ "default_title" : " table-sort" ,
13+ "default_popup" : " popup/table-options.html"
14+ },
1115 "content_scripts" : [
1216 {
1317 "matches" : [
1721 ],
1822 "js" : [" addTableSortClass.js" ," getTableHeaders.js" ," table-sort.js" ]
1923 }
20- ],
21-
22- "browser_action" : {
23- "default_icon" : " ./icons/t.png" ,
24- "default_title" : " table-sort" ,
25- "default_popup" : " popup/table-options.html"
26- }
27-
24+ ]
2825}
Original file line number Diff line number Diff line change 11<!DOCTYPE html>
22< html lang ="en ">
3- < head >
4- < meta charset ="UTF-8 ">
5- < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6- < title > Popup</ title >
7- </ head >
8- < body >
9- < div id ="popup-content ">
10- < button > table1</ button >
11- < button > table2</ button >
12- < button > table3</ button >
13- < button > table4</ button >
14- </ body >
3+ < head >
4+ < meta charset ="UTF-8 " />
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
6+ < title > Popup</ title >
7+ </ head >
8+ < body >
9+ < div id ="popup-content ">
10+ < button > table1</ button >
11+ < button > table2</ button >
12+ < button > table3</ button >
13+ < button > table4</ button >
14+ </ div >
15+ < script src ="../setButtons.js "> </ script >
16+ </ body >
1517</ html >
Original file line number Diff line number Diff line change 1+ // let tables = window.document.querySelectorAll("table");
2+ // console.log(getTableHeaders())
3+ let headers = document . querySelectorAll ( "table th" ) ;
4+ console . log ( headers )
5+ let headerNames = Array . from ( headers ) . map ( ( header ) => header . innerText ) ;
6+ console . log ( "nnnn" ) ;
7+
8+
9+ headerNames . forEach ( ( name ) => {
10+ const btn = document . createElement ( "button" ) ;
11+ console . log ( name ) ;
12+ btn . innerText = name ;
13+
14+ document . querySelector ( "#popup-content" ) . appendChild ( btn ) ;
15+ let test = document . querySelector ( "#popup-content" ) ;
16+ console . log ( test ) ;
17+ } )
You can’t perform that action at this time.
0 commit comments