Created
May 11, 2012 01:31
-
-
Save kozo002/2656934 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| window.Zenra = (function() { | |
| function Zenra(user_config) { | |
| var default_config = { | |
| subjects: '私 僕 俺 君 わたし ぼく おれ きみ 貴方 あなた'.split(/\s/), | |
| conjunctions: 'は が'.split(/\s/) | |
| }; | |
| if (typeof user_config === 'undefined') { | |
| user_config = {subjects:[], conjunctions:[]}; | |
| } | |
| this.subjects = merge(default_config.subjects, user_config.subjects); | |
| this.conjunctions = merge(default_config.conjunctions, user_config.conjunctions); | |
| this.z = '全裸で'; | |
| } | |
| // public | |
| Zenra.prototype.define = function() { | |
| var self = this; | |
| String.prototype.zenra = function() { | |
| var str = this.replace(/_/, '_'); | |
| each(self.subjects, function(i, subject) { | |
| each(self.conjunctions, function(_i, conjunction) { | |
| var word = subject + conjunction; | |
| var word_e = new RegExp(word, 'g'); | |
| if (str.match(word_e)) { | |
| str = str.replace(word_e, word + self.z); | |
| return false; | |
| } | |
| }); | |
| }); | |
| return str; | |
| }; | |
| }; | |
| // private | |
| var each = function(items, func) { | |
| for (var key in items) { | |
| var result = func(key, items[key]); | |
| if (result === false) { | |
| break; | |
| } | |
| } | |
| }; | |
| var merge = function() { | |
| var args, length, result, item, arg; | |
| args = Array.prototype.slice.call(arguments); | |
| length = args.length; | |
| result = {}; | |
| for(var i = 0; i < length ; i++){ | |
| arg = args[i]; | |
| for (item in arg) { | |
| if (arg.hasOwnProperty(item)) | |
| result[item] = arg[item]; | |
| } | |
| } | |
| return result; | |
| }; | |
| return Zenra; | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment