// ==UserScript==
// @name           Japanese DLSite translation
// @description    Replaces Japanese text on DLSite
// @include        *dlsite.com/*
// @exclude        *dlsite.com/ecchi-eng/*
// @run-at         document-start
// ==/UserScript==

//////////////////////////////////////////////////////////////////////////////////////////
var wordStarts = {
    '日' : '',
    '検索条件' : 'Search for',
    '円' : ' JPY',
//Advanced Search
    '件' : ' pages',
};

//////////////////////////////////////////////////////////////////////////////////////////
var wordContains = {
    '対象性別' : 'Audience',
    '男性向け' : 'Males',
    'ロールプレイングゲーム' : 'RPG',
    'サークル一覧' : 'Circles',
    '成人向けすべて' : 'Adult All',
    '成人向け同人' : 'Adult Doujin',
    '成人向けPCソフト' : 'Adult PC soft',
    '同人ゲーム' : 'Doujin Game',
    'アプリケーション' : 'Executable File',
    'バージョンアップ情報' : 'Upgrade Information',
    '販売日' : 'Release',
    '最終更新日' : 'Last Modified',
    '年齢指定' : 'Age Ratings',
    '18禁' : 'R18+',
    '作品形式' : 'Categories',
    'ファイル形式' : 'File Format',
    '対応OS' : 'OS Platforms',
    'その他オプション' : 'Additional Options',
    'その他同人誌' : 'Other Doujins',
    'その他同人ソフト' : 'Other Doujin Soft',
    'その他ゲーム' : 'Other Games',
    'その他' : 'Other',
    'マイジャンル' : 'Tags',
    'サンプル' : 'Samples',
    'HTML版で表示' : 'Display in HTML format',
    'ホームページ' : 'Website',
    'サークル名' : 'Circle',
    '並び替え' : 'Sort by',
    '件中' : 'Total',
    '件目' : 'Showing',
    '発売日が新しい順' : 'Release date - New to Old',
    '発売日が古い順' : 'Release date - Old to New',
    'DL数が多い順' : 'Numer of Dowloads',
    '価格が安い順' : 'Price - Low to High',
    '価格が高い順' : 'Price - High to Low',
    '評価が高い順' : 'Rating - High to Low',
    'レビューが多い順' : 'Reviews - High to Low',
    '表示件数' : 'Display',
    '表示形式' : 'View',
    '次へ' : 'Next',
    '最後へ' : 'Last Page',
    '最初へ' : 'First Page',
    '前へ' : 'Previous',
    'お気に入りに追加' : 'Favorite',
    'キーワード' : 'Keywords',
    '検索条件を変更する' : 'Modify search conditions',
    '保存した検索条件' : 'My Favorite',
    'ジャンル' : 'Tags',
    'の検索結果' : 'Results',
    '検索結果' : 'Results',
    '他の趣味嗜好で探す' : 'Advanced Search',
//Advanced Search
    'シリーズ名' : 'Series',
    'イベント' : 'Event',
    '作品名' : 'Title',
    'オプション' : 'Option',
    '割引中の作品' : 'Items at Discount',
    '専売/独占/先行作品' : 'DLsite Exclusive',
    '販売開始日' : 'Release Date',
    '指定なし' : 'All',
    '1週間以内' : 'Last 7 days',
    '1ヶ月以内' : 'Last 30 days',
    '1年以内' : 'Past 12 months',
    'それ以前' : 'Older',
    '価格帯' : 'Price Range',
    '円以下' : ' JPY and less',
    '円以上' : ' JPY and more',
    '販売状況' : 'Sale status',
    '販売中' : 'Works available for sale',
    '予告中' : 'Upcoming works',
    '指定しない' : 'All',
    '対象作品' : 'Target work',
    '同人作品' : 'Doujin',
    'PCゲーム' : 'PC game',
    '電子書籍' : 'E-book',
    '全年齢向け' : 'All ages',
    'R指定' : 'R-15',
    '成人向け' : 'Adult ',
    '表示順序' : 'Sort by',
    '通常表示' : 'Standard view',
    '画像のみ' : 'Gallery view',
//Categories
    'デジタルコミック' : 'Digital Comic',
    '劇画' : 'Gekiga',
    'イラスト集' : 'Illustration',
    'イラスト' : 'Illust',
    '同人ソフトノベル' : 'Doujin Software Novel',
    '同人誌ノベル' : 'Doujin Novel',
    '写真集' : 'Photo Album',
    'ツール/アクセサリ' : 'Utility / Tool',
    '素材' : 'Materials',
    '作品' : '',
    '音声あり' : 'Voiced',
    '音楽あり' : 'With Music',
    '動画あり' : 'With Video',
    'ロールプレイング' : 'RPG',
    'テーブルゲーム' : 'Table',
    'デジタルノベル' : 'Digital Novel',
    'シミュレーション' : 'Simulation',
    'タイピング' : 'Typing',
    '画集' : 'Artbooks',
    'ノベル' : 'Novel',
//Preferences
    '趣味嗜好' : 'Preferences',
    'いずれかを含む' : 'One or more of these words',
    '全てを含む' : 'All these words',
//Focus / Appeals
    'こだわり/アピール' : 'Focus / Appeals',
    '淡白/あっさり' : 'Plain/Nonpersisting',
    'お尻/ヒップ' : 'Buttocks',
    '淫語' : 'Dirty Talk',
    '連続絶頂' : 'Successive Orgasms',
    'ベタ/コテコテ' : 'Predictable Story',
//Featured Items / Tools
    'アイテム/道具' : 'Featured Items/Tools',
    'ピアス/装飾品' : 'Earrings',
    '首輪/鎖/拘束具' : 'Collar/Chain/Hamper',
    'ムチ/縄/蝋燭' : 'Whip/Rope/Candle',
    '包帯/注射器' : 'Bandage/Injector',
    '道具/異物' : 'Foreign Object',
//Characters
    'キャラクター' : 'Characters',
    '叔父/義父' : 'Uncle/Stepfather',
    '男性/おやじ' : 'Man/Middle-age',
    '同級生/同僚' : 'Classmate',
    '先輩/後輩' : 'Junior & Senior Students',
    '女王様/お姫様' : 'Queen/Princess',
    'エルフ/妖精' : 'Elf/Fairy',
    '天使/悪魔' : 'Angel/Demon',
    '魔法使い/魔女' : 'Witch',
    '人外娘/モンスター娘' : 'Nonhuman/Monster Girl',
    'レトロ/耽美' : 'Retro/Aesthetic',
    '芸能人/アイドル/モデル' : 'Entertainer/Idol/Model',
    '警察/刑事' : 'Police',
    'ヤクザ/裏社会' : 'Crime/Gangster',
    '不良/ヤンキー' : 'Bad Boy/Hoodlum',
    'レスラー/格闘家' : 'Wrestler/Fighter',
    'ヤリチン/プレイボーイ' : 'Playboy',
    'けもの/獣化' : 'Animalize',
//Outfits / Occupations
    'コスチューム/衣装/職業' : 'Outfits / Occupations',
    'レース/フリル' : 'Lacy/Frilled',
    '着物/和服' : 'Kimono/Japanese Dress',
//Situations / Tastes
    'シチュエーション/系統' : 'Situations / Tastes',
    '学校/学園' : 'School',
    'オフィス/職場' : 'Office',
    'ラブラブ/あまあま' : 'Romance',
    '退廃/背徳/インモラル' : 'Decadent/Immoral',
    '日常/生活' : 'Drama/Daily Living',
    '性転換(TS)' : 'Transsexual',
    '風俗/ソープ' : 'Soapland',
    '歴史/時代物' : 'Epic/Historical',
    'ノンフィクション/体験談' : 'Non-fiction/Real Story',
    '年下攻' : 'Younger Man (Dominant)',
//Actions / Sexual Pteferences
    'プレイ/えっち傾向' : 'Actions / Sexual Pref.',
    '妊娠/孕ませ' : 'Pregnancy/Impregnation',
    'レズ/女同士' : 'Lesbian',
    'ホモ/男同士' : 'Homosexual',
    '複数プレイ/乱交' : 'Orgy',
    '強制/無理矢理' : 'Coercion/Compulsion',
    '放尿/おしっこ' : 'Gold.Shower/Urination',
    'ごっくん/食ザー' : 'Cum Swallow',
//Appearance
    '外見/身体的特徴' : 'Appearance',
    '巨乳/爆乳' : 'Big Breasts',
    '貧乳/微乳' : 'Tiny Breasts',
    '複乳/怪乳/超乳' : 'Multiple Breasts',
    '乳首/乳輪' : 'Nipples',
    'ぼて腹/妊婦' : 'Pregnant Woman',
    'スリム/スレンダー' : 'Slim/Slender',
    '褐色/日焼け' : 'Tanned Skin/Suntan',
    'タトゥー/刺青' : 'Tattoo',
//Violence / Guro
    '残酷系/異常系' : 'Violence / Guro',
//Additional Options
    'グロテスクな表現を含む' : 'Contains grotesque imagery',
    'ホモセクシャルな表現を含む' : 'Contains homosexual imagery',
    'プロテクトを除外する' : 'Exclude copy-controlled works',
    '体験版あり' : 'Trial version',
    'レビューあり' : 'User reviews',
    'PDF同梱' : 'PDF File',
    'APK同梱' : 'APK File',
    'almight対応' : 'Almight engine',
    'ブラウザ試聴' : 'Browser streaming',
    '平均評価' : 'Average rating',
//Event
    'コミックマーケット' : 'Comic Market ',
//File Format
    'HTMLファイル' : 'HTML file',
    '+画像' : '+Image',
    '画像ファイル' : 'Image file',
    'Androidアプリファイル' : 'App file fоr Android',
    ')ファイル' : ')',
    'ファイル' : ' file',
    'ムービー' : 'Video ',
    'オーディオ(' : 'Audio (',
    '画像' : 'Image ',
    'オーディオ' : 'Audio',
    '動画' : 'Video',
    '音声' : 'Voice',
    '音楽' : 'Music',
//end of Advanced Search
//sidebar Preferences
    'ロリ ' : 'Loli ',
    '人妻 ' : 'Married Woman ',
    'ふたなり ' : 'Futanari/Dick girl ',
    '触手 ' : 'Tentacle ',
    '寝取られ ' : 'Netorare ',
    '催眠 ' : 'Hypnosis ',
    '逆レイプ ' : 'Woman Rapes Man ',
    '男性受け ' : 'Submissive Man ',
    '男の娘 ' : 'Trap ',
    '女体化 ' : 'Feminization ',
    '悪堕ち ' : 'Corrupted Morals ',
//other
    'ランキング' : 'Ranking',
    'DLsite専売' : 'Exclusives',
    'おすすめ特集' : 'Recommend',
    '発売カレンダー' : 'Releases',
    '発売予告' : 'Upcoming',
    '詳細検索' : 'Advanced Search',
};

//////////////////////////////////////////////////////////////////////////////////////////
var wordEquals = {
    '年' : '/',
    '月' : '/',
//Categories
    'マンガ' : 'Manga',
    'CG集' : 'CG Collection',
    'アクション' : 'Action',
    'クイズ' : 'Quiz',
    'アドベンチャー' : 'Adventure',
    'シューティング' : 'Shooter',
    'パズル' : 'Puzzle',
    'ゲーム' : 'Game',
//Focus / Appeals
    '萌え' : 'Moe',
    'ツンデレ' : 'Tsundere',
    '燃え' : 'Hot',
    '感動' : 'Tearjerker',
    '癒し' : 'Healing',
    '鬱' : 'Depression',
    'オールハッピー' : 'Totally Happy',
    '着衣' : 'Clothed',
    'チラリズム' : 'Peeping',
    'フェチ' : 'Fetish',
    '女性視点' : 'Woman\'s Viewpoint',
    '女主人公のみ' : 'Female Heroine Only',
    '男無' : 'No Male',
    '逆転無し' : 'No Reverse',
    'マニアック' : 'Maniac',
    'アブノーマル' : 'Abnormal',
    'おさわり' : 'Touching',
    'きせかえ' : 'Clothes Changing ',
    '脚' : 'Legs',
    'おっぱい' : 'Breasts',
    '汁/液大量' : 'Lots of Cum',
    '断面図' : 'Inside View',
    'ドット' : 'Pixel Art',
    'ポリゴン' : '3D',
    'アニメ' : 'Anime',
    '催眠音声' : 'Hypnotic Voice',
    'アンソロジー' : 'Anthology',
//Featured Items / Tools
    'リボン' : 'Ribbon',
    'カチューシャ' : 'Headband',
    'メガネ' : 'Glasses',
    '靴下' : 'Socks',
    '薬物' : 'Drug',
    'ローション' : 'Lotion',
    'スタンガン' : 'Stun Gun',
    'おむつ' : 'Diaper',
    'おもちゃ' : 'Toy',
//Characters
    'ぷに' : 'Puni',
    '少年' : 'Boy',
    '年上' : 'Senior',
    '母親' : 'Mother',
    '義妹' : 'Younger Stepsister',
    '義母' : 'Stepmother',
    '実姉' : 'Real Older Sister',
    '義姉' : 'Older Stepsister',
    '熟女' : 'Mature Woman',
    '人妻' : 'Married Woman',
    'お姉さん' : 'Older Girl/Older Sister',
    '未亡人' : 'Widow',
    '既婚者' : 'Married Person',
    '幼なじみ' : 'Childhood Friend',
    '双子' : 'Twins',
    '姉妹' : 'Sisters',
    '保健医' : 'School Nurse',
    '女医' : 'Female Doctor',
    '女教師' : 'Female Teacher',
    '教師' : 'Teacher',
    '学生' : 'Student',
    '委員長' : 'Class President',
    '上司' : 'Boss',
    'OL' : 'Office Lady',
    '秘書' : 'Secretary',
    'サラリーマン' : 'Salaried Worker',
    'ホスト' : 'Host',
    'リーマン' : 'Salariman',
    'お嬢様' : 'Upper-class Girl',
    'ギャル' : 'Gal',
    'ビッチ' : 'Bitch',
    '天然' : 'Natural',
    '電波' : 'Frantic',
    '主従' : 'Master and Servant',
    '執事' : 'Butler',
    '変身ヒロイン' : 'Transforming Girl',
    '魔法少女' : 'Magical Girl',
    '男の娘' : 'Trap',
    '妖怪' : 'Specter',
    '擬人化' : 'Personification',
    'ヤンデレ' : 'Yandere',
    'モンスター娘' : 'Monster Girl ',
    'ロボッ娘' : 'Robogirl ',
    'ドジっ娘' : 'Clumsy Girl',
    'ロボット' : 'Robot',
    'ガテン系' : 'Blue-collar Worker',
    '幽霊' : 'Ghost',
    'ゾンビ' : 'Zombie',
    '同性愛者' : 'Homosexual',
    'ショタケモ' : 'Furry (Shota)',
    'インテリ' : 'Intellectual',
    '外国人' : 'Foreigner',
    '体育会系' : 'Jock',
    'スポーツ選手' : 'Athlete',
    'ニューハーフ' : 'Shemale',
    '戦士' : 'Warrior',
    '俺様攻め' : 'Lordly Manner (Dominant)',
    'クール攻め' : 'Cool Man (Dominant)',
    'ヘタレ攻め' : 'Lazy (Dominant)',
    '強気受け' : 'Tough Guy (Submissive)',
    '誘い受け' : 'Seduce (Submissive)',
    'やんちゃ受け' : 'Mischievous (Submissive)',
    'オヤジ受け' : 'Older Man (Submissive)',
    'クール受け' : 'Cool Man (Submissive)',
    '健気受け' : 'Diligent Man (Submissive)',
    '乙女受け' : 'Girl (Submissive)',
    '少女' : 'Girl',
    '妹' : 'Younger Sister ',
    '兄' : 'Older Brother ',
    '弟' : 'Younger Brother ',
    '父' : 'Father ',
    '先輩' : 'Senpai ',
    'ショタ' : 'Shota ',
//Outfits / Occupations
    '制服' : 'Uniform',
    'セーラー服' : 'Sailor-style Uniform',
    '体操着' : 'Gym Clothes',
    '道着' : 'Judo Uniform',
    'スポユニ' : 'Sports Uniform',
    'メイド' : 'Maid',
    'ナース' : 'Nurse',
    '巫女' : 'Shrine Maiden',
    '軍服' : 'Army Uniform',
    '下着' : 'Underwear',
    'パンツ' : 'Panties',
    'ふんどし' : 'Loincloth',
    'ゴスロリ' : 'Gothic Lolita',
    'ロリ' : 'Loli',
    'コスプレ' : 'Cosplay',
    'ボンデージ' : 'Bondage',
    'ブルマ' : 'Gym Shorts',
    'チャイナ' : 'Chinese Dress',
    'ミニスカ' : 'Short Skirt',
    'エプロン' : 'Apron',
    'ラバー' : 'Rubber',
    'レオタード' : 'Leotard',
    '白衣' : 'White coat',
    'シスター' : 'Nun',
    'ワイシャツ' : 'Dress Shirt',
    'ウェイトレス' : 'Waitress',
    'バニーガール' : 'Bunny Girl',
    'スパッツ' : 'Leggings',
    'ニーソックス' : 'Knee Socks',
    'ストッキング' : 'Stockings',
    'ローレグ' : 'Low-cut Legs',
    'スクール水着' : 'School Swimsuit',
    '水着' : 'Swimsuit',
    'スーツ' : 'Suit',
    'ガードル' : 'Girdle',
    'ガーター' : 'Garter',
    '半ズボン' : 'Breeches',
    'ブレザー' : 'Blazer',
    '男装' : 'Cross-dressed Woman',
    '女装' : 'Crossdress',
    '社長' : 'President',
    '医者' : 'Doctor',
    'アイドル' : 'Idol',
//Situations / Tastes
    'ラブコメ' : 'Funny Love Story',
    '耳かき' : 'Ear Cleaning',
    '屋外' : 'Outdoor',
    'ギャグ' : 'Hilarious',
    '憑依' : 'Possession',
    '石化' : 'Petrifaction',
    '家族' : 'Family',
    'コメディ' : 'Comedy',
    '時間停止' : 'Time Stopping',
    'ミリタリー' : 'Military',
    'SF' : 'Sci Fi',
    'スポーツ' : 'Sports',
    '格闘' : 'Fight',
    'ほのぼの' : 'Heartwarming',
    '同棲' : 'Cohabitation',
    '恋人同士' : 'Lovers',
    '遠距離恋愛' : 'Long-distance Love',
    '初体験' : 'First Experience',
    '出会い' : 'Encounter',
    'サークル' : 'Circle',
    '色仕掛け' : 'Coquettish',
    '女体化' : 'Feminization',
    '浮気' : 'Cheating',
    '三角関係' : 'Love Triangle',
    '売春/援交' : 'Prostitution',
    'シリアス' : 'Serious',
    'ファンタジー' : 'Fantasy',
    'パラレル' : 'Parallel',
    'ホラー' : 'Horror',
    'キャットファイト' : 'Cat Fight',
    'スプラッター' : 'Splatter',
    'サスペンス' : 'Suspense',
    'ハードボイルド' : 'Hard-boiled',
    'バイオレンス' : 'Violence',
    'ギャンブル' : 'Gambling',
    'ヤキモチ' : 'Jealousy',
    'オカルト' : 'Occult',
    '歳の差' : 'May and December',
    '魔法' : 'Magic',
    '芸能' : 'Entertainment',
    '同居' : 'Roommate',
    '純愛' : 'Pure Love',
    '耽美' : 'Shonen-ai',
    '戦場' : 'War',
    'おもらし' : 'Urination',
    '伝奇' : 'Marvel Tales',
    'ティーンズラブ' : 'Teens Love',
    'ボーイズラブ' : 'Boys Love',
    'ハーレム' : 'Harem',
    'やおい' : 'Yaoi',
    '寝取られ' : 'Netorare',
    '百合' : 'Yuri',
    'ミステリー' : 'Mystery',
    '丸呑み' : 'Vore',
    '電車' : 'Train',
    '寝取り' : 'Netori',
    '歴史' : 'History',
//Actions / Sexual Pteferences
    '手コキ' : 'Hand Job',
    '足コキ' : 'Foot Job',
    'ぶっかけ' : 'Bukkake',
    '顔射' : 'Facial',
    '中出し' : 'Internal Cumshot',
    'パイズリ' : 'Breast Sex',
    '母乳' : 'Breast Milk',
    '搾乳' : 'Milking',
    '出産' : 'Childbirth',
    '産卵' : 'Egg Production',
    '陵辱' : 'Violation',
    'オナニー' : 'Masturbation',
    '緊縛' : 'Tight Binding',
    'フェラチオ' : 'Blowjob',
    '痴漢' : 'Molestation',
    '調教' : 'Sexual Training',
    '変態' : 'Hentai',
    '淫乱' : 'Naughty',
    '露出' : 'Outdoor Exposure',
    '言葉責め' : 'Oral Assault',
    '青姦' : 'Outdoor Sex',
    '拘束' : 'Restraint',
    '奴隷' : 'Slave',
    '浣腸' : 'Enema',
    '羞恥' : 'Ashamed',
    '恥辱' : 'Humiliation',
    '監禁' : 'Captivity',
    '焦らし' : 'Tease',
    'くすぐり' : 'Tickling',
    '鬼畜' : 'Pervert',
    'ノーマルプレイ' : 'Vanilla Sex',
    '放置プレイ' : 'Neglect Play',
    '無理矢理' : 'Coercion',
    '輪姦' : 'Gangbang',
    '和姦' : 'Consensual Sex',
    '近親相姦' : 'Incest',
    '逆レイプ' : 'Woman Rapes Man',
    '盗撮' : 'Upskirt/Spy Photo',
    '男性受け' : 'Submissive Man',
    '催眠' : 'Hypnosis',
    'アナル' : 'Anal',
    'スカトロ' : 'Scatology',
    '尿道' : 'Urethra',
    '触手' : 'Tentacle',
    '獣姦' : 'Bestiality',
    '機械姦' : 'Robot Sex',
    '拡張' : 'Stretch/Expansion',
    '下克上' : 'Junior\'s Domination',
    'ソフトエッチ' : 'Soft Erotic',
    'アヘ顔' : 'Ahegao',
    'モブ姦' : 'Nameless Sex',
    '異種姦' : 'Interspecies Sex',
    '悪堕ち' : 'Corrupted Morals',
    '洗脳' : 'Brainwashing',
    '口内射精' : 'Oral Cumshot',
    'イラマチオ' : 'Forced Oral',
    'スパンキング' : 'Spanking',
    'バイ' : 'Bisexual',
    'レイプ' : 'Rape',
//Appearance
    'ショートカット' : 'Short hair',
    'ロングヘア' : 'Long Hair',
    'おかっぱ' : 'Bobbed Hair',
    '茶髪' : 'Brown Hair',
    '金髪' : 'Blonde Hair',
    '黒髪' : 'Brunet Hair',
    '三つ編み' : 'Braid',
    'ポニーテール' : 'Ponytail',
    'ツインテール' : 'Twin Tail',
    'ネコミミ' : 'Cat Ears',
    '獣耳' : 'Animal Ears',
    '長身' : 'Tall Woman',
    '羽根' : 'Wings',
    '筋肉' : 'Muscular',
    'スレンダー' : 'Slender',
    'つるぺた' : 'Childlike Build',
    'パイパン' : 'Hairless',
    '陰毛/腋毛' : 'Pubic Hair',
    'ふたなり' : 'Futanari/Dick girl',
    '巨根' : 'Large Cock',
    '童貞' : 'Virgin/Intact Male',
    '処女' : 'Virgin Female',
    '巨大化' : 'Supersize',
    'しっぽ' : 'Tail',
    '関西弁' : 'Kansai Dialect',
    'ボクっ娘' : 'Tomboy',
    '無表情' : 'Deadpan',
    '包茎' : 'Phimosis',
    'むちむち' : 'Chubby/Plump',
    '太め' : 'Chubby',
    'デブ' : 'Fat',
    '爺' : 'Old Man',
//Violence / Guro
    '腹パン' : 'Gut Punch',
    '猟奇' : 'Psychotic',
    '人体改造' : 'Body Modification',
    '拷問' : 'Torture',
    'フィストファック' : 'Fist Sex',
    'ニプルファック' : 'Nipple Sex',
    '血液/流血' : 'Blood',
    '狂気' : 'Madness',
    'リョナ' : 'Ryona/Brutal',
    '蟲姦' : 'Worm Sex',
//Common
    '娘' : 'Daughter ',
//other
    '料理' : 'Cooking',
};

//////////////////////////////////////////////////////////////////////////////
// This is where the real code is
// Don't edit below this
//////////////////////////////////////////////////////////////////////////////

var skipTags = {input:true, textarea:true};
var boundaryChars = '[\\s,./?;:\'"/\\[\\]{}\\-_=+`~!@#$%^&*()<>|\\\\]';
var reEquals = new RegExp('(^|' + boundaryChars + ')(' + wordsAsRegexp(wordEquals) + ')(' + boundaryChars + '|$)', 'g');
var reStarts = new RegExp('(^|' + boundaryChars + ')(' + wordsAsRegexp(wordStarts) + ')', 'g');
var reContains = new RegExp(wordsAsRegexp(wordContains), 'g');

new MutationObserver(function(mutations) {
	for (var i=0, m; (m = mutations[i++]); ) {
		for (var j=0, node, added = m.addedNodes; (node = added[j++]); ) {
			switch (node.nodeType) {
				case Node.TEXT_NODE:
					doReplace(node);
					break;
				case Node.ELEMENT_NODE:
					var walker = document.createTreeWalker(node, NodeFilter.SHOW_TEXT);
					while (walker.nextNode()) {
						var textNode = walker.currentNode;
						if (skipTags[textNode.parentNode.localName] === undefined)
							doReplace(textNode);
					}
					break;
			}
		}
	}
}).observe(document, {subtree:true, childList:true});

function doReplace(textNode) {
	var text = textNode.nodeValue;
	var newText = text.replace(reContains, function(word) {
		return wordContains[word];
	}).replace(reStarts, function(s, prefix, word) {
		return prefix + wordStarts[word];
	}).replace(reEquals, function(s, prefix, word, suffix) {
		return prefix + wordEquals[word] + suffix;
	});
	if (newText !== text) {
		textNode.nodeValue = newText;
	}
}

function escapeStringForRegExp(s) {
	return s.replace(/[{}()\[\]\/\\.+?^$:=*!|]/g, "\\$&");
}

function wordsAsRegexp(words) {
	return escapeStringForRegExp(Object.keys(words).join(String.fromCharCode(1))).replace(/\x01/g, '|');
}