2016-08-15 74 views
1

我使用mark.js来标记正面(绿色),负面(红色)和中性(粗体)网站的某些部分。它突出了三个独立的时间,增加了一个类,然后用css进行样式设计。由于某些原因,代码不会标记我的单词列表中的某些单词。例如:http://imgur.com/a/hmGRC。应该突出显示“锁”一词。这里是另一个例子:http://imgur.com/a/PdQpy应该标记“issues”这个词。mark.js不突出显示单词?

var positive = [ "negotiable","leather","clean title","clean history", 
       "clean car history","clean vin","clean carfax","brand new", 
       "1 owner","one owner","original owner","sunroof","moonroof","Z71","texas edition", 
       "panoramic","panorama","convertable","nav","navigation","never been", 
       "OBO","or best offer", 
       "touch screen","touchscreen","voice","gps","camera","dvd", 
       "entertainment","tv","television","premium","plus","pkg","flex fuel","Moon Roofs","sun roofs","moonroofs","sunroofs", 
       "pack","package","turbo","alloy","chrome","aluminum","back up camera","backup camera","back up cam","backup cam", 
       "allwheel all-wheel awd?","camera","power drivers seat","Power Lift","sky slider","skyslider","skyview", 
       "power windows","hardtop","hard top","4wd","4x4","4 wheel","not had any problems","no problems", 
       "four wheel","awd","allwheel","all-wheel","power","powered","All wheel drive","leatherette","leatherett","leatheret", 
       "heated","heat","no accidents","no bumps","non smoker","Moon Roof","sun roof", 
       "non smoking","no smoking","non-smoker","non-smokers","NAVAGATION","LEATER", 
       "non-smoking","no dents","no scrapes","no issues","rust-free", 
       "no wreck","no accident" ]; 
var negative = [ "armada","quest","flex","aspen","veloster","5 series","defects","defect","Rebuild","ex-salvage","exsalvage","exsalvaged","salvage","salvaged", 
       "infiniti","monte carlo","avenger","impala","versa","mini","stains","stained","stain","local only","local buyers","locally only","sell local","sell locally", 
       "mitsubishi","sebring","tiburon","durango","e250","scratches","dings","ding","scratch","scratched","mark","marked","marks", 
       "e350","rx8","miata","fiat","smart","mazda6","pontiac","not working","won't work","doesn't work","dealers","body work","needs","needing", 
       "magnum","accent","rio","crossfire","pt cruiser","pacifica","minor","blemishes","blemish","blemished","rusted", 
       "rondo","chrysler 200","saab","rendezvous","lexus gs","sentra","supercharger","supercharged","super charge","super charged","super charger","tuner","chip","chipped", 
       "mx5","accord lx","grand marquis","solara","non-negotiable","rough country","no dealers","no dealer","if you are a dealer", 
       "not negotiable","custom rims","nitro","nos","injected","firm","cracked","crack","cracks","cracking","aftermarket","programmer", 
       "noticeable","collision","impact","rear-ended","rearended","damage","damaged","damaging","local only","locals only","only local","be local","local sale only","local buyer only","local buyers only", 
       "rear ended","blemish","barely","wrapped","flaw","loose","mod","incident","incidents","branded","title brand","New transmission", 
       "bump","hole","burn","rip","tear","puncture","flat","dent","problems","problem","issue","issues","Tune","tuning", 
       "accident","wreck","scratch","scrape","break","bust","broken","spill","spilt","splash","wet","scratching","fading","faded","fade", 
       "rebuilt","salvaged","deploy","lowball","low-ball","repair","faulty","chips","h3","h3x","does not","leveling kit", 
       "fix","fixed","rust","hail","leak","torn","bent","stain","replace","replaced","Lowering","program","programming","programmed", 
       "scuff","problem","bad","horrible","stink","stank","stunk","dents","worn","fender bender","bender", 
       "lift","lifted","lowered","new york","nyc","new jersey","Rock Krawler", 
       "miami","lauderdale","doesn't work","stopped working", 
       "isn't working","do not","slight","modified","tuned","chipped", 
       "chip","burst","modification","vibrate","cosmetic","wrecked" ]; 
var neutral = [ "transmission","tread","automatic","manual","2wd","rwd","fwd","small", 
       "4x2","2 wheel","two wheel","seat","diesel","kelly","paperwork","leveling","level","leveled", 
       "v8","v6","v10","v4","v5","custom","sound system","good","great","auto","trans","we","i","us","moving","our","I've","we've", 
       "rims","excellent","condition","amazing","roof","cruise","remote","warranty", 
       "push","bucket","amp","liftgate","lift gate","liter","kit","rim","seats","3rd","third row","tires", 
       "wheels","lift gate","vin","17 inch","18 inch","19 inch","carpet","stock","never", 
       "20 inch","21 inch","22 inch","23 inch","24 inch","17\"","18\"","xm","sirius","satellite", 
       "19\"","20\"","21\"","22\"","23\"","24\"","impact","crew","supercrew","replaced","replace","replacing", 
       "cab","supercab","crew cab","exhaust","locks","window","driver","tinted","tint", 
       "seat","door","running board","runningboard","extra","edition","mile","miles","milages","mileage", 
       "ex-l","lx","kbb","loaded","appointment","maintenance","dealership","bluetooth", 
       "dealer","sport","luxury","reasonable","asap","lease","finance","pay", 
       "lien","loan","bank","limited","driver","very fair","old","dog","pet", 
       "animal","elderly","trim","cloth","owners","smell","airbag", 
       "title in hand","in hand","hemi","engine","must sell","personal", 
       "negotiate","price","coupe","dual","towing","hatchback","wagon","wife","son","father","mother","daughter","college","student","elderly", 
       "bus","sedan","truck","suv","trade","garage","reduced","stereo", 
       "five-speed","six-speed","fivespeed","liter","cylinder","tint","row","Running Boards","runningboard","running board","interior","certified", 
       "adult","teenager","teenage","daughter","son","college","father", 
       "mother","grandfather","grandson","grandmother","granddaughter", 
       "death","family","emergency","moving","carfax","cheap","title", 
       "nada","blue book","smoke","pet","owner","upgrade","new","subs","I have","I may","I owned","I've had","I've owned", 
       "subwoofer","amplifier","after market","installed", 
       "condition","contact","via","call","cell","telephone","phone", 
       "evening","morning","anytime","reach","email","text","number", 
       "owned","had this","my","photo","evidence","proof","photograph", 
       "picture","more info","hybrid","electric","customer", 
       "best offer","current offer","top offer","declined","decline", 
       "reject","refuse","owe","cash","money","$","no" ]; 
var names = [ "honda", "toyota", "ford","XLT","Escape","Chevy","Silverado","1500","2500","Edge","lariat","lariet", 
       "LT","LTZ","Crew Cab","Extended Cab","Dodge","Ram","quad cab","2006","2007", 
       "2008","2009","2010","2011","2012","2013","2014","2015","2016","fx4", 
       "Rav4","Jeep","Compass","Commander","Liberty","Wrangler","Unlimited","Limited","ltd","Sahara","Rubicon","Patriot", 
       "Acura","MDX","technology","RDX","xl","xlt","f150","f250","f350","f-150","f-250","f-350" ]; 
var brands = [ "Acura", "Audi", "Buick", "Cadillac", "Chevrolet", "Chevy", "Chrysler", "Dodge", "Ford", "GMC", 
       "Honda", "Hummer", "Hyundai", "Jeep", "Kia", "Land Rover", "Landrover", "Lexus", "Lincoln", 
       "Mazda", "Mercedes-Benz", "Mercedes", "Mercury", "Nissan", "Scion", "Subaru", "Toyota", 
       "Volkswagen", "VW", "Volvo" ]; 


_ready = function() { 
    _formatBody(); 
}; 

_formatBody = function(n) { 
    var body = n && $(n).closest('body') || $('body'); 

var instance = new Mark(document.querySelector("#postingbody")); 
instance.mark(positive, { 
      accuracy: "exactly", 
      separateWordSearch: false, 
      className: "positive" 
}); 
var instance = new Mark(document.querySelector("#postingbody")); 
instance.mark(negative, { 
      accuracy: "exactly", 
      separateWordSearch: false, 
      className: "negative" 
}); 

var instance = new Mark(document.querySelector("#postingbody")); 
instance.mark(neutral, { 
      accuracy: "exactly", 
      separateWordSearch: false, 
      className: "neutral" 
}); 
$('.positive').css({'color': '#0f6f00', 'font-weight': 'bold', "background-color":"transparent"}); 
$('.negative').css({'color': '#bd0000', 'font-weight': 'bold', "background-color":"transparent"}); 
$('.neutral').css({'font-weight':'bold', "background-color":"transparent"}); 

    body.find('.mapbox, .tsb, footer').remove(); 

    _checkValue(body); 
}; 

呀“复制”并没有真正包含任何这些错误的家伙不得不

+0

@gotnull被报道在控制台上没有错误 – TheGuyWhoCodes

+0

@Guedes这个JavaScript是一种tampermonkey脚本的一部分,所以没有CSS样式表!不确定你的意思是异步 – TheGuyWhoCodes

+1

HTML在哪里? – fuzz

回答

2

的既然你没有提供任何HTML来指代。

这是一个如何突出传递给实例的数组中的单词的工作示例。

var brands = [ "Acura", "Audi", "Buick", "Cadillac", "Chevrolet", "Chevy", "Chrysler", "Dodge", "Ford", "GMC", 
 
       "Honda", "Hummer", "Hyundai", "Jeep", "Kia", "Land Rover", "Landrover", "Lexus", "Lincoln", 
 
       "Mazda", "Mercedes-Benz", "Mercedes", "Mercury", "Nissan", "Scion", "Subaru", "Toyota", 
 
       "Volkswagen", "VW", "Volvo" ]; 
 

 
var instance = new Mark(document.querySelector("body")); 
 

 
instance.mark(brands, { 
 
    accuracy: { 
 
     value: "exactly", 
 
     limiters: [".", ",", "!"] 
 
    } 
 
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/7.0.0/mark.min.js"></script> 
 
<body> 
 
    <div>Hyundai Jeep Samsung Mercedes-Benz Nike Apple Nissan Scion!</div> 
 
</body>

+0

嘿!我把你的代码粘贴在我的jsfiddle底部(http://jsfiddle.net/e4dpe5jo/4/),它似乎并没有突出显示单词Scion – TheGuyWhoCodes

+0

字边界意味着空白或搜索上下文的开始/结束。在你的情况下,“问题”后面跟着一个“!”,这就是没有突出显示的原因。查看我的更新答案以获得修复。 – fuzz