筆記編輯部分也是一個document元素,document.title是“Evernote”,不是網頁的標題“印象筆記網頁版”,如何獲取頁面第一個title
使用查找title元素,編輯框加載后還是顯示“Evernote”
var tit = document.querySelector("title")
console.log(tit.innerHTML)
沒有足夠的數據
(??? )
暫時沒有任何數據
12style 提出了問題 · 3月8日
筆記編輯部分也是一個document元素,document.title是“Evernote”,不是網頁的標題“印象筆記網頁版”,如何獲取頁面第一個title
使用查找title元素,編輯框加載后還是顯示“Evernote”
var tit = document.querySelector("title")
console.log(tit.innerHTML)
筆記編輯部分也是一個document元素,document.title是“Evernote”,不是網頁的標題“印象筆記網頁版”,如何獲取頁面第一個title使用查找title元素,編輯框加載后還是顯示“Evernote”
關注 2 回答 1
12style 提出了問題 · 2月25日
使用下面JavaScript方法都可以獲取網易云音樂搜索框input元素
document.querySelector("input");
document.getElementById('srch');
在控制臺執行也可以聚焦
window.setTimeout(function(){ document.getElementById("srch").focus();}, 6000);
設置快捷鍵在頁面執行,報錯Cannot read property 'focus' of null
document.addEventListener('keydown',function(event) {
var keynum = event.which;
//ALT+H
if(keynum==72 && event.altKey){
var searchBar = document.querySelector("input[name=wd],input[type=text],input[name=srch],input[autocomplete],input[type=search]")
if(searchBar !== null){
searchBar.focus();
}else {
document.getElementById('srch').focus();;
}
}
});
使用下面JavaScript方法都可以獲取網易云音樂搜索框input元素 {代碼...} {代碼...} 在控制臺執行也可以聚焦 {代碼...} 設置快捷鍵在頁面執行,報錯Cannot read property 'focus' of null {代碼...} [鏈接]
關注 2 回答 1
12style 提出了問題 · 2月20日
在文本框劃詞,有文字會顯示getSelection為true,如果劃詞全部是空格,如何判斷呢
找了網上判斷字符串為空格的,都沒辦法實現
var te = window.getSelection().toString();
if(te.match(/^[ ]*$/)){
console.log("OK")
}
在文本框劃詞,有文字會顯示getSelection為true,如果劃詞全部是空格,如何判斷呢找了網上判斷字符串為空格的,都沒辦法實現 {代碼...}
關注 2 回答 1
12style 收藏了問題 · 2月1日
1.let obj = {k1:'香蕉', k2:'蘋果', k3:'橘子'};
2.什么好方法可以將obj中的k2和k3這兩個屬性同時刪除。
1.let obj = {k1:'香蕉', k2:'蘋果', k3:'橘子'}; 2.什么好方法可以將obj中的k2和k3這兩個屬性同時刪除。
12style 回答了問題 · 1月31日
讀取存儲在tampermonkey數據,存在新建的數組里面,再排序
讀取存儲在tampermonkey數據,存在新建的數組里面,再排序
關注 1 回答 1
12style 提出了問題 · 1月31日
我想把網站打開的次數和時間存儲在tampermonkey,我直接存儲發現不能排序,因為數組沒有名稱,如何將嵌套數組存放在tampermonkey,再通過次數排序,顯示到控制臺?
在這個腳本上添加了count函數https://greasyfork.org/zh-CN/scripts/404859
function count(a) {
let d = new Date();
if(GM_getValue(a)){
GM_setValue(a, {
'times': GM_getValue(a).times + 1,
'date': d
});
}else{
GM_setValue(a, {
'times': 1,
'date': d
});
}
}
油猴存儲數據
{
"Github": {
"times": 1,
"date": "2021/01/31 4:5:1"
},
"Google": {
"times": 2,
"date": "2021/01/31 12:11:33"
},
"Greasyfork": {
"times": 1,
"date": "2021/01/31 4:1:21"
},
}
然后我發現對數組排序的方法,需要存放在有名字的嵌套數組里面,這樣寫了只能存放當前打開的圖標網站的次數和時間,打開其他的圖標網站會被覆蓋
function count(a) {
let d = new Date();
if(GM_getValue('Times')){
GM_getValue('Times').forEach(function(value) {
if(value.name === a){
var m = [{
'name': a,
'times': value.times + 1,
'date': timetext
}]
GM_setValue('Times', m);
}else{
m = [{
'name': a,
'times': 1,
'date': timetext
}]
GM_setValue('Times', m);
}
});
} else {
var m = [{
'name':a,
'times': 1,
'date': timetext
}]
GM_setValue('Times', m);
}
}
數組排序的方法
let allValue = GM_listValues();
allValue.splice(allValue.indexOf('search'),1);
allValue.sort(compare( "times"));
function compare( propertyName) {
return function( object1, object2) {
var value1 = object1[propertyName];
var value2 = object2[propertyName];
if (value1 < value2) {
return 1;
} else if (value1 > value2) {
return - 1;
} else {
return 0;
}
}
}
如果油猴存放的數據是嵌套數組,就可以調用排序的函數了,達到的效果是這樣
{
"search": "",
"Times": [
{
"name": "Github",
"times": 6,
"date": "2021/01/31 18:43:15"
},
{
"name": "Google",
"times": 4,
"date": "2021/01/31 18:43:15"
},
{
"name": "Greasyfork",
"times": 1,
"date": "2021/01/31 18:43:15"
}
]
}
我想把網站打開的次數和時間存儲在tampermonkey,我直接存儲發現不能排序,因為數組沒有名稱,如何將嵌套數組存放在tampermonkey,再通過次數排序,顯示到控制臺?
關注 1 回答 1
12style 提出了問題 · 1月30日
我想將每個圖標打開的次數分別存儲在油猴里面,建了一個數組分別存放圖標的名稱、圖片、鏈接、彈出的信息,彈出的信息是一個函數,點擊圖標時執行打開鏈接和統計次數
我需要在函數里面引用當前的圖標的名稱,如何通過JavaScript實現呢?或者是否有其他的辦法?
在這個腳本基礎上改的劃詞腳本
var iconArray = [
{
name: 'Google',
image: 'https://i.ibb.co/R9HMTyR/1-5.png',
host: ['www.google.com'],
popup: function (text, name) {
open('https://www.google.com/s?wd=' + encodeURIComponent(text), name);
console.log(name);
}
},
{
name: 'Bing',
image: 'https://i.ibb.co/R9HMTyR/1-5.png',
host: ['www.bing.com'],
popup: function (text, name) {
open('https://www.bing.com/s?wd=' + encodeURIComponent(text), name);
console.log(name);
}
},
]
function open(url, a) {
try {
if(GM_openInTab(url, { loadInBackground: true, insert: true, setParent :true })){
if(GM_getValue(a).times){
GM_setValue(a, {
'times': GM_getValue(a).times + 1
});
}else{
GM_setValue(a, {
'times': 1
});
}
console.log('times-'+GM_getValue(a).times);
} else{
}
} catch (error) {
return GM_openInTab(url, { loadInBackground: true, insert: true, setParent :true });
}
}
我想在油猴里面這樣存放數據,打開Google 1次,Bing 4次
{
"Google": {
"times": "1",
},
"Bing": {
"times": "4",
},
}
我想將每個圖標打開的次數分別存儲在油猴里面,建了一個數組分別存放圖標的名稱、圖片、鏈接、彈出的信息,彈出的信息是一個函數,點擊圖標時執行打開鏈接和統計次數
關注 2 回答 2
12style 收藏了問題 · 2020-12-13
簡化創建的iconArray這個對象
var iconArray =
{
icona: document.createElement('div'),
iconb: document.createElement('div'),
iconc: document.createElement('div')
}
簡化創建的iconArray這個對象 {代碼...}
查看全部 個人動態 →
(??? )
暫時沒有
(??? )
暫時沒有
注冊于 2020-05-04
個人主頁被 390 人瀏覽
推薦關注
我要該,理由是: