Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi all,

I have no experience with javascript before, but I would like to convert the javascript below to vb.net, I really hope someone who expert on it will help me.

What I have tried:

<pre>window.onload = function () {
    // get m3u8 urls for current active tab
    window.bg_wnd = chrome.extension.getBackgroundPage();
    var m3u8_urls = window.bg_wnd.bg.get_m3u8_urls();

    // function render m3u8 urls list
    render_m3u8_urls(m3u8_urls);
	  
};



function render_m3u8_urls(m3u8_urls) {
    var content = document.getElementById('content');

    if (!m3u8_urls || !m3u8_urls.length) {
        content.innerHTML = '<a href="player.html" target="_blank" class="books"><sup >My bookmarks</sup></a><span class="mdi mdi-access-point-remove mdi-36px"  style="float:left;color:#666"><h5 class="not-found" style="color:#666;"> m3u8 requests no found</h5>';
        return;
    }
    
    var trs = [];
    for (var i = 0, cnt = m3u8_urls.length; i < cnt; i++) {
        var m3u8_url = m3u8_urls[i];
        trs.push('<a target="_blank" class="auto_start_download" title="auto start download" href="player.html#' + m3u8_url + '" ><div class="link" style=""><div style="float:left;"></div>' + 
                 '<div class="content" style="line-height:26px;white-space: nowrap;" title="' + m3u8_url + '">' + m3u8_url + '</div></div></a>');
    }
    var download_all = '<a href="player.html" target="_blank" class="books"><sup>My bookmarks</sup></a><br><span class="mdi mdi-access-point-check mdi-36px" style="float:left"><h5 class="found"><a class="download_all" title="download all" href="#">m3u8 urls: ' + m3u8_urls.length + '</a></h5>';
    var auto_start_download_all = ((1 < m3u8_urls.length) ? '' : '');
    content.innerHTML = '<table><tr><td>' + auto_start_download_all + '</td><td>' + download_all + '</td></tr></table>' +
                        '<div class="content">' + trs.join('') + '</div>';

    
}
Posted
Comments
Dave Kreskowiak 26-Jan-24 22:41pm    
Well, you have a major problem. First, nobody is going to convert the code for you, so if that's what you meant by "help", you need to change your expectations.

Next, Javascript code runs in a web browser, while VB.NET does not. So what are you trying to do with all of this code?

No one else can undertake this task on your behalf since nobody has complete logic or understanding of your application; you must handle it independently with some code converter tools if you dont have understanding of JavaScript, better to learn some basic here JavaScript For Beginners[^] .
Primarily, two platforms involved one is client-side and the other server-side code. Take the artifacts and identify the methods that require conversion from the client to the server side, following utilize any online converter to accomplish this task. You can refer to the following link to start conversion CodeConvert AI - Convert code with a click of a button[^]
 
Share this answer
 
To add to what the others have said, This is not a code conversion service: we are not here to translate code for you.
Even if we did, what you would end up with would not be "good code" in the target language – they are based on very different frameworks, and what makes something work in one language does not always "translate" directly into another.
So what you end up with is very poor code, that is difficult if not impossible to maintain, that can’t be upgraded nicely, and that will cause you immense headaches if the original is changed. And it'll be a nightmare to debug if it doesn’t work "straight out of the box".
Instead, use the source code as a specification for a new app written in and for the target language / framework and write it from scratch using the original as a "template". You will get a much, much better result that will save you a lot of time in the long run.

And the problem gets even worse in this case because not only do the languages share little in common, they are based on totally different frameworks, and are intended to be run in completely different environments:
Javascript is a client side language that runs in a sandbox (the browser) and is very tolerant of code errors as far as the user is concerned - it is embedded in a webpage by it's server which generates HTML and sends it back to the browser for rending into a displayable format for presentation.
VB is a server or desktop language which communicates with the user directly (or via HTML with the browser)

Trying to convert it "blindly" is going to be a major headache: you would need to work out how the heck to replace the browser based framework and HTML dependance with something that work directly to the user. And that means knowing both languages very well, as well as understanding the whole task that fragment is intended to implement.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900