पर मिलान करने वाले शब्दों को बदलें, मैं क्रोम एक्सटेंशन बनाने की कोशिश कर रहा हूं जो खोजशब्दों की तलाश में एक वेबसाइट के माध्यम से पार्स करता है, फिर उन कीवर्ड को बटन के साथ बदल देता है। हालांकि, जब मैं पाठ बदलता हूं तो छवि पथ दूषित हो जाता है।बटनों को वेबपृष्ठ के टेक्स्ट में
// This is a content script (isolated environment)
// It will have partial access to the chrome API
// TODO
// Consider adding a "run_at": "document_end" in the manifest...
// don't want to run before full load
// Might also be able to do this via the chrome API
console.log("Scraper Running");
var keywords = ["sword", "gold", "yellow", "blue", "green", "china", "civil", "state"];
// This will match the keywords with the page textx
// Will also create the necessary buttons
(function() {
function runScraper() {
console.log($('body'));
for(var i = 0; i < keywords.length; i++){
$("body:not([href]):not(:image)").html($("body:not([href]):not(:image)").html()
.replace(new RegExp(keywords[i], "ig"),"<button> " + keywords[i] + " </button>"));
console.log("Ran it " + i);
}
}
function createResourceButton() {
// Programatically create a button here
// Really want to return the button
return null;
}
function createActionButton() {
}
runScraper();
})();
// TODO create the functions that the buttons will call
// These will pass data to the chrome extension (see message passing)
// Or we can consider a hack like this:
// "Building a Chrome Extension - Inject code in a page using a Content script"
// http://stackoverflow.com/questions/9515704
वर्तमान परिणामों की छवि:
आपका चयनकर्ता 'बॉडी' तत्व को पकड़ता है और इसके आंतरिक HTML को बदल देता है इस प्रकार किसी भी संलग्न ईवेंट श्रोताओं को तोड़ देता है। साथ ही, जब आप अपने चयनकर्ता को ठीक करते हैं तो आपको तत्वों को बदलने के लिए '.each() 'का उपयोग करना होगा। – wOxxOm
क्या आप वास्तव में लिंक में प्रदर्शित शब्दों को बनाना चाहते हैं (यानी '' तत्वों में) बटन में, या बस अनुरोध है क्योंकि लिंक तोड़ दिए गए हैं? क्या आप लिंक के प्रदर्शित टेक्स्ट में मेल खाने वाले शब्दों को बटन में रखना चाहते हैं यदि यह लिंक तोड़ नहीं देता है? – Makyen