W pracy związanej z SEO (katalogowanie, uzupełnianie zaplecza) niezmiernie często tworzy się teksty z synonimami typu „{Bardzo|Niezwykle} {miło|fajnie} {Cię|Ciebie} {jest|było} {poznać|spotkać}.” Super fajna sprawa, ale jak tu na szybko wygenerować z tego tekst? Z pomocą przychodzi oto prosty skrypt napisany w js no i oczywiśie z elementami html. Kod skryptu zamieszczam poniżej. A demo znajduje się na stronie okazwłoka.pl/spiner.html
KOD:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Article Spinner</title> </head> <body> <div style="min-height:500px;"> <table cellpadding="5" cellspacing="5" border="0" align="center" width="800px"> <tr> <td> Spyntax content:<br /> <textarea id="textSpin" rows="10" style="width:100%;"></textarea> <input id="chkNewLine" type="checkbox" />Convert newline to <br /> </td> </tr> <tr> <td> <input id="inpSpin" type="button" value="Next Spun" onclick="Spin();" /> <input id="inpHtml" type="button" value="Html Code" onclick="Html(this);" style="display:none;" /> </td> </tr> <tr> <td> <textarea id="textHtml" rows="10" style="width:100%;display:none;"></textarea> <label id="lblSpin"></label> </td> </tr> </table> </div> <div style="text-align:center;">Provided by <a href="http://www.weontech.com">www.WeOnTech.com</a> - Auto Blog Network - Blog Post SEO - LinkWheel SEO</div> <script type="text/javascript"> function Html(obj) { if (obj.value == 'Html Code') { document.getElementById("textHtml").value = document.getElementById("lblSpin").innerHTML; document.getElementById("textHtml").style.display = "block"; document.getElementById("lblSpin").style.display = "none"; document.getElementById("inpHtml").value = "Preview"; } else { document.getElementById("textHtml").style.display = "none"; document.getElementById("lblSpin").style.display = "block"; document.getElementById("inpHtml").value = "Html Code"; } } function Spin() { var content = document.getElementById("textSpin").value.trim(); if (content == "") { alert("Please input spyntax content!"); } else if (content.split("{").length != content.split("}").length) { alert("Incorrect spyntax in content! Please re-check it!"); } else { if (document.getElementById("chkNewLine").checked) { var regX = /\n/gi; content = content.replace(regX, "<br />"); } document.getElementById("lblSpin").innerHTML = GetSpinContent(content); document.getElementById("inpHtml").style.display = ""; if (document.getElementById("inpHtml").value == "Preview") document.getElementById("textHtml").value = document.getElementById("lblSpin").innerHTML; } } function GetSpinContent(text) { var result = text; var reg = new RegExp(/{([^{}]*)\}/i); while (matches = reg.exec(result)) { var array = new Array(); array = matches[1].split('|'); result = result.replace(matches[0], array[Math.floor(Math.random() * array.length)]); } reg = new RegExp(/\{\{([\s\S]*?)\}\}/i); while (match = reg.exec(result)) { var array = new Array(); array = match[1].split('||'); result = result.replace(match[0], array[Math.floor(Math.random() * array.length)]); } return result; } </script> </body> </html> |
Komentarze