简体   繁体   English

我正在为网站制作JavaScript扩展程序。 我想改用Java或C#。 可能吗?

[英]I'm making a JavaScript extension for a site. I'd like to use Java or C# instead. Is it possible?

This is hard for me to explain and even harder for me to visualize how I'd do it, since I don't know the bounds of communication with websites with Java and C#, so if I banter a lot/make no sense in the process of describing this, I apologize. 这对我来说很难解释,甚至更难以想象我是如何做到的,因为我不知道与Java和C#网站的沟通范围,所以如果我在很多时候戏弄/没有意义在描述这一过程中,我道歉。

Basically, I'm making a 'bot' for www.plug.dj . 基本上,我正在为www.plug.dj制作一个“机器人”。 This bot is able to do things on command like kick users, ban users, send chat messages, delete chat messages, say random things, etc. As of right now, it's powered by a simple one-file JavaScript code with a ton of listeners and callbacks using the Plug.dj API to handle them. 这个机器人可以按照命令做事,比如踢用户,禁止用户,发送聊天消息,删除聊天消息,说随机等等。截至目前,它由一个简单的单文件JavaScript代码和大量的听众提供支持和回调使用Plug.dj API来处理它们。 This is ALL engineered by JS -- on the back-end, I think Plug.dj is powered by Python, I could be wrong. 这是由JS设计的 - 在后端,我认为Plug.dj是由Python驱动的,我可能是错的。

Anyway, what I would LIKE to do is create this bot on a language other than JS. 无论如何,我想做的是用JS以外的语言创建这个机器人。 It's really basic and not super powerful, and there are things like communicate with databases and such that I'd like to implement that aren't possible/convenient with JS. 它是非常基本的而不是超级强大的,并且有一些事情,比如与数据库进行通信,以及我想用JS实现那些不可能/不方便的事情。 I just want to know if this is possible, and if so, where should I start looking? 我只是想知道这是否可行,如果是的话,我应该从哪里开始寻找?

I'd prefer a language like Java or C#. 我更喜欢Java或C#这样的语言。 If there's any more info you need to know in order to answer this, let me know, please! 如果您需要了解更多信息以便回答此问题,请告诉我们! I'd like to start working on this, I think it'd be fun to learn how to communicate with websites with Java/C#/whatever. 我想开始研究这个问题,我认为学习如何使用Java / C#/无论如何与网站进行通信都会很有趣。

If the bot javascript runs on "their" server, then there is no simple solution. 如果bot javascript在“他们的”服务器上运行,那么就没有简单的解决方案。 They are providing a mechanism for running "your" javascript on their server, but the chances are that they don't support other languages. 他们提供了一种在他们的服务器上运行“你的”javascript的机制,但很可能他们不支持其他语言。 (And the only way to find out would be to ask "them"). (找出答案的唯一方法就是问“他们”)。 Assuming that the answer is "no", you would need to investigate whether you can implement your "bot"s functionality in client-side code; 假设答案是“否”,您需要调查是否可以在客户端代码中实现“bot”功能; eg a custom client that you implemented from scratch in Java or C# or whatever. 例如,您从头开始用Java或C#或其他方式实现的自定义客户端。 That's a big "if" ... because it will only work if they expose the server functionality you need in their external APIs. 这是一个很大的“if”......因为只有当它们在外部API中公开您需要的服务器功能时它才会起作用。

OTOH, if the bot javascript runs on "your" server, then you should be able to change it to support other languages. OTOH,如果bot javascript在“你的”服务器上运行,那么你应该能够改变它以支持其他语言。 (It wouldn't necessarily be easy though ...) (虽然......不一定容易)


My advice would be to take a deep breath ... and stick with Javascript. 我的建议是深呼吸......并坚持使用Javascript。 We all have to use languages that we don't think are "fun". 我们都必须使用我们认为不“有趣”的语言。

I honestly would just leave it in javascript if it is something you need to have run in the client. 老实说,如果你需要在客户端运行它,我会把它留在javascript中。

If you need to make database calls, you can introduce a web services layer in between against which you can make AJAX calls which interact with databases. 如果需要进行数据库调用,可以在两者之间引入一个Web服务层,您可以根据该层进行与数据库交互的AJAX调用。

I think your perception of javascript as basic and not very powerful is not a very good one. 我认为你对javascript的看法是基本的而不是非常强大的并不是一个非常好的。 They are very complex apps build today in just javascript and HTML5. 它们是目前仅使用javascript和HTML5构建的非常复杂的应用程序。 You just might need to start looking at things like backbone.js, underscore.js, and similar libraries that can help provide more advanced code organization functionality available to you. 您可能需要开始查看backbone.js,underscore.js和类似的库,这些库可以帮助您提供更高级的代码组织功能。

If however you are looking at building something that individual clients are not going to have installed in their browsers, but rather would just interact with the website in an automated admin, then certainly you can establish you own web service in whatever language you like to interact with their API's and perform admin tasks. 但是,如果您正在构建个人客户端不会在其浏览器中安装的内容,而只是在自动化管理中与网站进行交互,那么您当然可以使用您喜欢的任何语言建立自己的Web服务使用他们的API并执行管理任务。

If they provide a JavaScript library that runs client side, it seems likely that it will be communicating with the server over HTTP. 如果他们提供了一个运行客户端的JavaScript库,它似乎可能会通过HTTP与服务器通信。 Therefore, it should be possible for you to analyse the library and the calls it makes to reverse engineer the server API (which would be the HTTP calls) and re-implement it in the language of your choice. 因此,您应该可以分析库以及它对反向工程服务器API(这将是HTTP调用)所做的调用,并以您选择的语言重新实现它。

Looking at the code of bot.js : 看一下bot.js的代码:

https://github.com/backus/Plug.DJ-Javascript-Chatbot/blob/master/bin/bot.js https://github.com/backus/Plug.DJ-Javascript-Chatbot/blob/master/bin/bot.js

it seems everything comes down to calls against their API object, eg API.getDJs() , API.getWaitList() etc. If you can determine how this API object works, then you might be able to reverse engineer and re-implement. 似乎一切都归结为针对其API对象的调用,例如API.getDJs()API.getWaitList()等。如果您可以确定此API对象的工作方式,那么您可以进行反向工程和重新实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想使用union作为C#和字节数组 - I'd like to use union as C# with byte array 在固定类型大小的lang中,我应该在64位上使用“ long”而不是“ int”吗? - Should I use 'long' instead of 'int' on 64-bits in langs with fixed type size (like Java, C#) 在 C# 中制作我的第一个计算器,我被卡住了 - Making my first calculator in C# and I'm stuck 我想使用 TimeSpan 结构而不是 int- Selenium c# - I would like to use a TimeSpan structure instead of an int- Selenium c# 我想使用预定义的 ContentDialog(在 MainPage 上)来显示在 AppWindow 内。 这个怎么做? - I want to use the a predefined ContentDialog (on the MainPage) to be displayed inside an AppWindow instead. How to do this? 我在 C# (Unity3d) 中的镜像 API 中使用什么代替 NetworkBehaviour - What do I use instead of NetworkBehaviour in mirror API in C# (Unity3d) 为什么这个C#函数表现得像我在使用指针? - Why is this C# function behaving like I'm using pointers? 我可以通过Java而不是C#使用Brokerage的API吗? - Can I Use My Brokerage's API With Javascript Instead Of C#? 当我在 C# 中创建 JSON 帖子时,如何返回 HTTP 状态代码? - How do I return the HTTP status code when I'm making a JSON post in C#? 我如何使用C#泛型字典,就像在Java中使用Hashtable一样? - How do I use C# generic Dictionary like the Hashtable is used in Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM