Git Product home page Git Product logo

Comments (9)

xioxin avatar xioxin commented on May 20, 2024

输入框提示等等功能就不好实现了

from ehsyringe.

Mapaler avatar Mapaler commented on May 20, 2024

这是数据库的json格式吗?

from ehsyringe.

xioxin avatar xioxin commented on May 20, 2024

from ehsyringe.

OpportunityLiu avatar OpportunityLiu commented on May 20, 2024

只要你的node能匹配attribute node,其实翻译内容和属性没啥区别

from ehsyringe.

xioxin avatar xioxin commented on May 20, 2024

更新了结构

from ehsyringe.

xioxin avatar xioxin commented on May 20, 2024

不知道能不能用eval

from ehsyringe.

Mapaler avatar Mapaler commented on May 20, 2024

脚本内可以用eval的

from ehsyringe.

xioxin avatar xioxin commented on May 20, 2024

另外 可以使用tabs.executeScript 替代现在用的content_scripts 将数据直接构建到代码里,就可以摆脱对localStorage的依赖还能简化数据同步的逻辑,executeScript是异步的,不知道的可靠性怎么样,如果代码没有在body的dom加载之前注入的话可能会导致翻译失效。

browser.tabs.onUpdated.addListener(async (tabId: number, changeInfo, tab) => {
    if(changeInfo['status'] != 'loading') return;
    const id = tabId;
    console.log('tab onUpdated', tabId, changeInfo, tab);
    console.log(tagDatabase.tagList.value);
    const code = `
    console.log('test');
        window.tagData = ${JSON.stringify(tagDatabase.tagList.value, null, 2)};
        function test(node) {
            if(node.nodeName == '#text' && node.parentNode && node.parentNode.nodeName != 'SCRIPT' )node.textContent = node.textContent + '🐹';
        }
        const observer = new MutationObserver(mutations => mutations.forEach(mutation =>
            mutation.addedNodes.forEach(node1 => {
                test(node1);
                if (this.documentEnd && node1.childNodes) {
                    const nodeIterator = document.createNodeIterator(node1);
                    let node = nodeIterator.nextNode();
                    while (node) {
                        test(node);
                        node = nodeIterator.nextNode();
                    }
                }
            })
        ));
        observer.observe(window.document, {
            attributes: true,
            childList: true,
            subtree: true
        });
     `;
    await browser.tabs.executeScript(id, {
        code: `
            const script = document.createElement('script');
            script.innerHTML = \`${code.replace(/`/igm, '\\`').replace(/\\/igm, "\\\\")}\`;
            document.head.appendChild(script);
        `,
        runAt: "document_start",
    });
});

from ehsyringe.

DiamondYuan avatar DiamondYuan commented on May 20, 2024

是不是可以通过拦截 HTTP 请求来实现翻译。

from ehsyringe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.