Hash Code

Javascript implementation of Java’s String.hashCode() method

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/466055/1189121/Hash%20Code.js

  1. // ==UserScript==
  2. // @namespace i2p.schimon.hashcode
  3. // @exclude *
  4.  
  5. // ==UserLibrary==
  6. // @name Hash Code
  7. // @description Javascript implementation of Java’s String.hashCode() method
  8. // @author wes (Manwe Security Consulting)
  9. // @copyright 2010, wes
  10. // @homepageURL https://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/
  11. // @license MIT
  12. // @version 1.0.0
  13.  
  14. // ==/UserScript==
  15.  
  16. // ==/UserLibrary==
  17.  
  18. // ==OpenUserJS==
  19. // @author sjehuda
  20. // ==/OpenUserJS==
  21.  
  22. String.prototype.hashCode = function(){
  23. let hash = 0;
  24. if (this.length == 0) return hash;
  25. for (let i = 0; i < this.length; i++) {
  26. let char = this.charCodeAt(i);
  27. hash = ((hash<<5)-hash)+char;
  28. hash = hash & hash; // Convert to 32bit integer
  29. }
  30. return hash;
  31. };

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址