V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
songz
V2EX  ›  JavaScript

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

  •  
  •   songz · 2018-01-06 23:34:13 +08:00 · 4248 次点击
    这是一个创建于 2272 天前的主题,其中的信息可能已经有所发展或是发生改变。

    平時喜歡看開眼的視頻,但是在 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">

    求大佬,請喝咖啡

    15 条回复    2018-07-24 10:11:10 +08:00
    Dexter123
        1
    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
        2
    songz  
    OP
       2018-01-07 00:01:58 +08:00
    @Dexter123 #1 貌似並不可以,不知道是不是我用的方法不對呢,我是複製在油猴裏,油猴下標顯示 1
    Dexter123
        3
    Dexter123  
       2018-01-07 00:05:29 +08:00
    @songz 把最后的 100 改成 200 试试 不行就 1000
    Dexter123
        4
    Dexter123  
       2018-01-07 00:06:28 +08:00
    r#2 @songz 加上 // @match http*://www.eyepetizer.net/*
    Dexter123
        5
    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
        6
    lsvih  
       2018-01-07 00:10:27 +08:00   ❤️ 1
    // ==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
        7
    songz  
    OP
       2018-01-07 00:10:43 +08:00
    @Dexter123 #4 可以啦~但是全部都變成一個地址了~不是縮略圖對應的視頻
    cnilnhf
        8
    cnilnhf  
       2018-01-07 00:10:52 +08:00   ❤️ 1
    (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
        9
    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
        10
    Dexter123  
       2018-01-07 00:11:44 +08:00   ❤️ 1
    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
        11
    huai  
       2018-01-07 00:16:51 +08:00 via iPhone   ❤️ 1
    哈哈 来个 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
        12
    songz  
    OP
       2018-01-07 00:19:25 +08:00
    @lsvih #6
    @Dexter123 #10
    這兩位,留個帳戶,我發個紅包
    songz
        13
    songz  
    OP
       2018-01-07 00:22:08 +08:00
    @huai #11 這個語法對於我這種 0 基礎的比較好理解~
    huai
        14
    huai  
       2018-01-07 00:28:40 +08:00 via iPhone
    @songz #13 哈哈,楼上几位 es6 的我也想写,后面想想算了。写个简单明了的,更好
    songz
        15
    songz  
    OP
       2018-07-24 10:11:10 +08:00
    @lsvih #6 开眼换了域名,油猴也报错了,可以更新一下语句吗? https://www.kaiyanapp.com/
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3378 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 13:15 · PVG 21:15 · LAX 06:15 · JFK 09:15
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.