vladgba / Back2source

Userscript for redirect to source sites from sites with machine translation, etc.
The Unlicense
37 stars 1 forks source link

codefactor.io -> github.com #16

Closed KaKi87 closed 2 years ago

KaKi87 commented 2 years ago

Thanks

CennoxX commented 2 years ago

I don't think it makes sense to redirect codefactor.io as the site isn't a simple mirror.

KaKi87 commented 2 years ago

Ok, maybe. It's just that I'm tired of seeing search results pointing to websites displaying data that doesn't belong to those.

CennoxX commented 2 years ago

Hm I understand. @vladgba what's your thought, should we add it?

vladgba commented 2 years ago

@CennoxX Hi, I think we should add. But in the future, we need to add a mechanism to disable it if someone does not need a redirect.

CennoxX commented 2 years ago

I'm sorry to hear, hope you are safe. Yes, these pages are clones and not official mirrors, I'll add the pages.

KaKi87 commented 2 years ago

Another one : lifesaver.codes (example)

Thanks

CennoxX commented 2 years ago

@vladgba codefactor.io redirects always to the repository, even if a specific file is opened, which is a good, but not the best solution. Example: https://www.codefactor.io/repository/github/cennoxx/userscripts/file/main/scripts/Wikidata%20Episode%20Generator.user.js redirects to https://github.com/CennoxX/userscripts. There is a GitHub-link on file pages (Actions > View file on GitHub), but I can't get our script using this, as it isn't there on document-end, when back2source starts...

vladgba commented 2 years ago

@CennoxX I'm sorry I didn't pay attention to that. Found some solution: (bad but working)

let sf = 'li[ng-if*="model.FileExternalUrl"]>a, a[ng-if*="model.FileExternalUrl"], a.page-title-link, a[title="GitHub"]';
let to = setTimeout(() => {
    let dq = _t(sf);
    if(dq?.href?.indexOf('github.com') >= 0) {
        clearTimeout(to);
        _go(dq.href);
    }
}, 1000);
return;

have any ideas for improvement?

CennoxX commented 2 years ago

@vladgba I came up with another solution: wait for the document, then use normal selectors:

case 'codefactor.io':
    document.addEventListener("DOMContentLoaded", (e)=>{
        let sf = 'a[analytics-event^="View file on"]';
        if (!_t(sf)){
            sf = 'a[title^="View on"]';
        }
        if (_t(sf)){
            return _go(bySel(sf));
        }
    });
    break;

This works for GitHub and Bitbucket. It waits for the document, searches for "View file on ... (GitHub/Bitbucket)", if that's not there it searches for "View on ... (GitHub/Bitbucket)" and goes there, if it exists.