Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var list = "apple, りんご, orange, みかん, orangejuice, おれんじじゅーす";
- // ↑をカンマ区切りで設定してね
- var dict = list.split(/\s*,\s*/);
- if (dict.length % 2 != 0) { throw new Error("単語数が奇数になってる"); }
- for (var i = 0; i < dict.length / 2; i++) { dict[i] = [dict[i * 2].replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), dict[i * 2 + 1]]; }
- dict.length /= 2;
- dict.sort(function(a, b) { return b[0].length - a[0].length; });
- if (document.selection.Text == "") { document.selection.SelectAll(); }
- var text = document.selection.Text;
- for (var i = 0; i < dict.length; i++) { text = text.replace(dict[i][0], dict[i][1]); }
- document.selection.Text = text;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement