用于将 devanagri 音译为古吉拉特语的 Mozilla 扩展

发布于 2024-10-24 15:50:54 字数 5513 浏览 4 评论 0原文

我已经为 mozilla firefox 按钮创建了一个扩展,它将音译特定的网页。 按钮代码粘贴在mozilla的%appdata%中。button.js的代码如下所示,

function doSomething()
{ 
    let url = "http://localhost/aaa/trial.asp";
  let request = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Components.interfaces.nsIXMLHttpRequest);
   request.onload = function(aEvent) {

    doc=gBrowser.contentDocument;
    doc.body.innerHTML = "<div>" + gBrowser.contentDocument.body.innerHTML  + "</div>";
    doc.body.innerHTML = "<div style='background-color: gray' >" + aEvent.target.responseText + "</div>"   + gBrowser.contentDocument.body.innerHTML;
    doc.body.innerHTML = gBrowser.contentDocument.body.innerHTML + "<div  id='in_trans_overlay'><a id='in_trans_lnk' href='javascript:hide(0); void 0;'>click here  to see the original page</a></div>" ;
    doc.getElementById("in_trans_overlay").style.left="0px";
    doc.getElementById("in_trans_overlay").style.top="0px";
    doc.getElementById("in_trans_overlay").style.position="fixed"; 
    doc.getElementById("in_trans_overlay").style.backgroundColor="blue";
    //doc.getElementById("in_trans_overlay").style.opacity="0.4";
    doc.getElementById("in_trans_overlay").style.width="100%";
    doc.getElementById("in_trans_overlay").style.zIndex="10";
    doc.getElementById("in_trans_lnk").style.color="white";
    //doc.getElementById("in_trans_lnk").style.opacity="1.0";

    doc.body.childNodes[1].style.display="none";

    hd=doc.getElementsByTagName("head");
    scpt=doc.createElement("script");
    scpt.setAttribute("type", "text/javascript");
    scpt.setAttribute("charset", "UTF-8");
    scpt.setAttribute("src", "http://localhost/aaa/hide.js");
    hd[0].appendChild(scpt);
   };
   request.onerror = function(aEvent) {
        window.alert("Error Status: " + aEvent.target.status );
   };

   request.open("POST", url, true);
   request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   params = gBrowser.contentDocument.body.innerHTML;

   params = "inTransContent=" + encodeURIComponent(params);
   request.setRequestHeader("Content-length", params.length);
   request.setRequestHeader("Connection", "close");

   request.send(params);

}

此代码发送一个xmlhttp请求,它将执行Trial.asp代码。

Trial.asp 包含以下代码,

<% Dim xmlDoc 
Dim objNodeList
    Dim count

    set xmlDoc = Server.CreateObject("Msxml2.DOMDocument.6.0")

    xmlDoc.validateOnParse = False
    xmlDoc.async = False

    xmlDoc.loadXML("<div>" & Request.Form("inTransContent")   & "</div>")   

    If (xmlDoc.parseError.errorCode <> 0) Then
        Dim myErr
        Set myErr = xmlDoc.parseError
        Response.Write("<div><br><br><br>" & myErr.reason & "<br>" & myErr.line & "<br>" & myErr.srcText & "</div>")
    Else
          Set objNodeList = xmlDoc.documentElement.selectNodes("//text()")
          count = objNodeList.length

          For i = 1 To count 
               objNodeList(i-1).insertData 0, "XYZ " 
               objNodeList(i-1).insertData objNodeList(i-1).length, " XYZ" 
          Next 

          Response.Write(xmlDoc.documentElement.xml)
   End If

%>

该代码将仅发送要音译的文本节点,因为我在 for 循环中没有取得太大进展,所以我将其替换为虚拟的..在之前和末尾附加 xyz。我需要转换这个 asp 代码,因为我要去 asp.net。我需要将其转换为 vb.net 或 c# 代码..我稍后会回到 for 循环..此代码应该成为 asp.net 中的 default.aspx 文件。

接下来是 asp.net 我需要一个 global.asax 文件 global.asax 文件包含此代码,

    protected void Application_Start(object sender, EventArgs e)
    {
        sbyte[,] a = new sbyte[100, 100];
        sbyte[,] b = new sbyte[100, 100];
        int count = 0;
        XDocument docA = XDocument.Load("dev.xml");
        XDocument docB = XDocument.Load("guj.xml");
         var devanagriKeys = (from d in docA.Descendants("mapping")
                                              select new {
                                                  Key = d.Descendants("itrans").FirstOrDefault().Value,
                                                  Character = d.Descendants("character").FirstOrDefault().Value
                                              }).ToArray();
        var gujrathiKeys = (from g in docB.Descendants("mapping")
                                              select new {
                                                  Key = g.Descendants("itrans").FirstOrDefault().Value,
                                                  Character = g.Descendants("character").FirstOrDefault().Value
                                              }).ToArray();
        var crossReference = (from d in devanagriKeys
                              join g in gujrathiKeys on d.Key equals g.Key
                              select new {
                                    d.Key,
                                    Devanagri = d.Character,
                                    Gujrathi = g.Character
                                }).ToList();

此代码将从 devanagri 脚本和 gujrathi 脚本中获取字符,并使用 itrans 作为一种媒介创建一个列表,例如 अ in itrans is a while અ in gujarati has the same itrans a 因此将创建一个列表来存储 अ 和 અ 因为它们具有相同的 itrans。

这里我需要将这个列表存储在会话变量中,以便我可以在default.asp中使用它。 但我无法正确地弄清楚这一点。

我告诉过我将回到 default.aspx 的 for 循环,所以现在在这个 default.aspx 中我必须搜索并将 devanagri 的每个文本节点替换为古吉拉特语,反之亦然。

我也很困惑,因为我正在使用一个iis服务器,所以我应该将asp.net的所有项目文件复制到iis的inetpub的wwwroot文件夹中。

如果有人指导我,我将不胜感激!我对很多代码感到抱歉..我陷入了困境,所以我真的需要帮助,如果对此有任何疑问,请随时发布,谢谢!

i have created an extension for mozilla firefox button,which will transliterate a particular webpage.
the button code is pasted in %appdata% of mozilla.the code for button.js is as follows

function doSomething()
{ 
    let url = "http://localhost/aaa/trial.asp";
  let request = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Components.interfaces.nsIXMLHttpRequest);
   request.onload = function(aEvent) {

    doc=gBrowser.contentDocument;
    doc.body.innerHTML = "<div>" + gBrowser.contentDocument.body.innerHTML  + "</div>";
    doc.body.innerHTML = "<div style='background-color: gray' >" + aEvent.target.responseText + "</div>"   + gBrowser.contentDocument.body.innerHTML;
    doc.body.innerHTML = gBrowser.contentDocument.body.innerHTML + "<div  id='in_trans_overlay'><a id='in_trans_lnk' href='javascript:hide(0); void 0;'>click here  to see the original page</a></div>" ;
    doc.getElementById("in_trans_overlay").style.left="0px";
    doc.getElementById("in_trans_overlay").style.top="0px";
    doc.getElementById("in_trans_overlay").style.position="fixed"; 
    doc.getElementById("in_trans_overlay").style.backgroundColor="blue";
    //doc.getElementById("in_trans_overlay").style.opacity="0.4";
    doc.getElementById("in_trans_overlay").style.width="100%";
    doc.getElementById("in_trans_overlay").style.zIndex="10";
    doc.getElementById("in_trans_lnk").style.color="white";
    //doc.getElementById("in_trans_lnk").style.opacity="1.0";

    doc.body.childNodes[1].style.display="none";

    hd=doc.getElementsByTagName("head");
    scpt=doc.createElement("script");
    scpt.setAttribute("type", "text/javascript");
    scpt.setAttribute("charset", "UTF-8");
    scpt.setAttribute("src", "http://localhost/aaa/hide.js");
    hd[0].appendChild(scpt);
   };
   request.onerror = function(aEvent) {
        window.alert("Error Status: " + aEvent.target.status );
   };

   request.open("POST", url, true);
   request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   params = gBrowser.contentDocument.body.innerHTML;

   params = "inTransContent=" + encodeURIComponent(params);
   request.setRequestHeader("Content-length", params.length);
   request.setRequestHeader("Connection", "close");

   request.send(params);

}

this code sends an xmlhttprequest and it will execute trial.asp code.

trial.asp contains the following code

<% Dim xmlDoc 
Dim objNodeList
    Dim count

    set xmlDoc = Server.CreateObject("Msxml2.DOMDocument.6.0")

    xmlDoc.validateOnParse = False
    xmlDoc.async = False

    xmlDoc.loadXML("<div>" & Request.Form("inTransContent")   & "</div>")   

    If (xmlDoc.parseError.errorCode <> 0) Then
        Dim myErr
        Set myErr = xmlDoc.parseError
        Response.Write("<div><br><br><br>" & myErr.reason & "<br>" & myErr.line & "<br>" & myErr.srcText & "</div>")
    Else
          Set objNodeList = xmlDoc.documentElement.selectNodes("//text()")
          count = objNodeList.length

          For i = 1 To count 
               objNodeList(i-1).insertData 0, "XYZ " 
               objNodeList(i-1).insertData objNodeList(i-1).length, " XYZ" 
          Next 

          Response.Write(xmlDoc.documentElement.xml)
   End If

%>

this code will send only the text nodes which are to be transliterated,since i havent progressed much in the for loop so i have replaced it with dummy..which appends xyz before and at the end. i need to convert this asp code because i am going to asp.net. i need to convert this to vb.net or c# code..i will come back to the for loop later..this code should become the default.aspx file in asp.net.

the next thing which is asp.net is that i need a global.asax file
the global.asax file contains this code

    protected void Application_Start(object sender, EventArgs e)
    {
        sbyte[,] a = new sbyte[100, 100];
        sbyte[,] b = new sbyte[100, 100];
        int count = 0;
        XDocument docA = XDocument.Load("dev.xml");
        XDocument docB = XDocument.Load("guj.xml");
         var devanagriKeys = (from d in docA.Descendants("mapping")
                                              select new {
                                                  Key = d.Descendants("itrans").FirstOrDefault().Value,
                                                  Character = d.Descendants("character").FirstOrDefault().Value
                                              }).ToArray();
        var gujrathiKeys = (from g in docB.Descendants("mapping")
                                              select new {
                                                  Key = g.Descendants("itrans").FirstOrDefault().Value,
                                                  Character = g.Descendants("character").FirstOrDefault().Value
                                              }).ToArray();
        var crossReference = (from d in devanagriKeys
                              join g in gujrathiKeys on d.Key equals g.Key
                              select new {
                                    d.Key,
                                    Devanagri = d.Character,
                                    Gujrathi = g.Character
                                }).ToList();

this code will take characters from devanagri script and gujrathi script and create a list using itrans as one medium for eg अ in itrans is a while અ in gujarati has same itrans a
so a list will be created storing अ and અ because they are having same itrans.

here i need to store this list thing in a session var so that i can use it in the default.asp..
i cant figure that one out properly though.

i had told that i will come back to the for loop of default.aspx, so now in this default.aspx i have to search and replace every text node of devanagri to gujarati and vice versa..

i am also confused because i am using a iis server so i am i supposed to copy all the project files of asp.net in the wwwroot folder of inetpub of iis.

i will be thankful if anyone guides me to this!! i am sorry for lots of code..i am stuck badly so i really needed help, if any queries regarding this please feel free to post thanks!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魂ガ小子 2024-10-31 15:50:54

听起来您想在 ASP 页面和 .NET .ASPX 页面之间共享会话变量中的项目。我理解正确吗?

请考虑这篇文章:如何在经典 ASP 和 ASP.NET 之间共享会话状态

您最好将 .asp 转换为 .NET .aspx。考虑解决方案的可维护性。

It sounds like you want to share items in session variables between your ASP page and your .NET .ASPX page. Did I understand that correctly?

Consider this article: How to Share Session State Between Classic ASP and ASP.NET

You'd probably be better off converting your .asp to a .NET .aspx. Consider the maintainability of your solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文