求一個油猴腳本,鏈接替換

2018-01-06 23:34:13 +08:00
 songz

平時喜歡看開眼的視頻,但是在 pc 端的頁面並不方便

http://www.eyepetizer.net/detail.html?vid=71469

打開後可以播放該 vid 的視頻

但是

下方的列表視頻點擊打開後都跳到下載 app 頁面

所以求一個腳本,可以批量替換列表 裏面的地址

<a href="https://lkme.cc/3rC/4qQTa1dMJ" data-vid="68245">

改爲

<a href="http://www.eyepetizer.net/detail.html?vid=68245" data-vid="68245">

求大佬,請喝咖啡

4290 次点击
所在节点    JavaScript
15 条回复
Dexter123
2018-01-06 23:56:46 +08:00
(function() {
'use strict';

// Your code here...
setTimeout(()=>{
document.querySelector('.relate-video-list').querySelectorAll('a').forEach(a=>a.href=a.baseURI);
},100);

})();
songz
2018-01-07 00:01:58 +08:00
@Dexter123 #1 貌似並不可以,不知道是不是我用的方法不對呢,我是複製在油猴裏,油猴下標顯示 1
Dexter123
2018-01-07 00:05:29 +08:00
@songz 把最后的 100 改成 200 试试 不行就 1000
Dexter123
2018-01-07 00:06:28 +08:00
r#2 @songz 加上 // @match http*://www.eyepetizer.net/*
Dexter123
2018-01-07 00:09:24 +08:00
r#2 @songz 刚刚那个好像有 bug ; 完整的这个 我本地试了应该没问题了。。

// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match http*://www.eyepetizer.net/*
// @grant none
// ==/UserScript==

(function() {
'use strict';

// Your code here...
console.log(111);
setTimeout(()=>{

document.querySelector('.relate-video-list').querySelectorAll('a').forEach(a=>a.href=`http://www.eyepetizer.net/detail.html?vid=${a.dataset.vid}`);
},200);

})();
lsvih
2018-01-07 00:10:27 +08:00
// ==UserScript==
// @name eyepetizer
// @match http://www.eyepetizer.net/detail.html?vid=*
// @run-at document-start
// ==/UserScript==
(()=>setInterval(()=>document.querySelectorAll(".relate-video-list a").forEach(e=>e.href = `//www.eyepetizer.net/detail.html?vid=${e.dataset.vid}`),500))();

直接这样吧,简单粗暴

@Dexter123 那些链接 ajax 加载的,偷懒的话直接 setInterval 走起,不然还要去看啥时候加载完
songz
2018-01-07 00:10:43 +08:00
@Dexter123 #4 可以啦~但是全部都變成一個地址了~不是縮略圖對應的視頻
cnilnhf
2018-01-07 00:10:52 +08:00
(function() {
'use strict';

// Your code here...
setTimeout(()=>{
document.querySelector('.relate-video-list').querySelectorAll('a').forEach(a=>a.href=a.href = "http://www.eyepetizer.net/detail.html?vid=" + a.dataset.vid);
},100);

})();
iNaru
2018-01-07 00:11:15 +08:00
(function(){
const animationName = btoa(Math.random()).replace(/[^a-z]/ig, 'a');
document.head.appendChild(document.createElement('style')).textContent = `
@keyframes ${animationName} {from{opacity:.9;}to{opacity:1;}}
a[data-vid] {animation:${animationName} 1ms;}
`;
document.addEventListener('animationstart', e => {
if(e.animationName !== animationName) return;
e.target.href = e.target.baseURI;
});
})();
Dexter123
2018-01-07 00:11:44 +08:00
r#7 @songz 中间那句换成 document.querySelector('.relate-video-list').querySelectorAll('a').forEach(a=>a.href=`http://www.eyepetizer.net/detail.html?vid=${a.dataset.vid}`)
huai
2018-01-07 00:16:51 +08:00
哈哈 来个 jq 的。
// ==UserScript==
// @name OpenEyeScript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author None
// @match *://www.eyepetizer.net/detail.html?*
// @grant none
// @require http://lib.baomitu.com/jquery/1.9.1/jquery.min.js
// ==/UserScript==

(function() {
'use strict';
setTimeout(function(){
$('.relate-video-list a').each(function(){
var uid = $(this).data('vid');
$(this).attr('href',`http://www.eyepetizer.net/detail.html?vid=${uid}`);
});
},1e3);
})();
songz
2018-01-07 00:19:25 +08:00
@lsvih #6
@Dexter123 #10
這兩位,留個帳戶,我發個紅包
songz
2018-01-07 00:22:08 +08:00
@huai #11 這個語法對於我這種 0 基礎的比較好理解~
huai
2018-01-07 00:28:40 +08:00
@songz #13 哈哈,楼上几位 es6 的我也想写,后面想想算了。写个简单明了的,更好
songz
2018-07-24 10:11:10 +08:00
@lsvih #6 开眼换了域名,油猴也报错了,可以更新一下语句吗? https://www.kaiyanapp.com/

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/420715

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX