[ Príspevkov: 3 ] 
AutorSpráva
Offline

Užívateľ
Užívateľ
Obrázok užívateľa

Registrovaný: 02.10.06
Prihlásený: 09.09.10
Príspevky: 29
Témy: 12 | 12
NapísalOffline : 28.03.2009 11:41 | Replace Text on web

Nazdar, mal by som jednu prosbu. Na internete som nasiel tento userscript pre Greasemonkey, ktory sluzi na zmenu textu, napr. miesto lol napise lot of laughts a podobne. Funguje perfektne, ja by som vsak potreboval, aby na stranke zmenil len prve slovo. napr. v clanke je 4x spomenute slovo depresia a ja by som chcel aby to prve slovo premenoval na depka a ostatne tri nechal napokoj. Dalo by sa to nejako urobit? Toto je zdrojak skriptu

Kód:
// ==UserScript==
// @name           Replace Text On Webpages
// @namespace      http://userscripts.org/users/23652
// @description    Replaces text on websites. Now supports wildcards in search queries
// @include        http://*
// @include        https://*
// @include        file://*
// @exclude        http://userscripts.org/scripts/review/*
// @copyright      JoeSimmons
// ==/UserScript==

var words = {
///////////////////////////////////////////////////////
// Syntax: 'Search word' : 'Replace word',
'im*o' : 'in my opinion', // Will get imo and any characters between m and o
///////////////////////////////////////////////////////
'4.5' : '12','6' : '71'};


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

// Grab the text nodes
var this_text, text = document.evaluate("//text()[normalize-space(.)!='']",document,null,6,null);

for(var i=text.snapshotLength-1; i>=0; i--) {


// Create a shortcut for the text node
this_text = text.snapshotItem(i);

// Iterate the words array
   for(word in words) {
   
   // Turn the search term into a regular expression
   // allowing wildcards (*) to be used for any character
   var search_regexp = new RegExp(word.replace(/\*/g,'.*'), 'gi');
   
   // Exclude the blank option at the bottom of the array words
   // so every entry can have a comma after it for easy entry of blacklisted words
   // And if the text node contains the blacklisted word
   // And if the text isn't inside a link
      if(word!='' && search_regexp.test (this_text.textContent) && this_text.parentNode.tagName!='A') {
      
      // Replace the blacklisted word with the appropriate word
      this_text.textContent = this_text.textContent.replace(search_regexp, words[word]);
      
      }
      
   }
   
}


_________________
PC::Základná doska : Asus P4U800-X, Čipset : Ali Uli 1633 M, Procesor : Intel Celeron D @ 2660 MHz, Chladič : Arcting Colling Super Ultra TC, Fyzická pamäť : 1536 MB (1 x 1024 DDR400, 1 x 512 DDR400), Grafická karta : Sparkle Geforce 7600 GS 512 MB, Pevný disk :Hitachi 80 GB, Jednotka DVD-RW : LG GSA H55L, Operačný systém : Microsoft Windows Seven Ultimate RC, DirectX : Verzia 11

NB::Samsung R510, Intel Celeron Dual Core @ 1830 MHz, 2 GB DDR2 ram, 160 GB Samsung HDD, Intel GMA 4500 MHD, 15,4 " displej
Offline

Čestný člen
Čestný člen
Replace Text on web

Registrovaný: 11.08.07
Príspevky: 4088
Témy: 34 | 34
Bydlisko: Brno
NapísalOffline : 28.03.2009 12:36 | Replace Text on web

Skus
Kód:
new RegExp(word.replace(/\*/g,'.*'), 'gi');
nahradit s
Kód:
new RegExp(word.replace(/\*/g,'.*'), 'i');


Offline

Užívateľ
Užívateľ
Obrázok užívateľa

Registrovaný: 02.10.06
Prihlásený: 09.09.10
Príspevky: 29
Témy: 12 | 12
Napísal autor témyOffline : 28.03.2009 12:43 | Replace Text on web

nepomohlo


_________________
PC::Základná doska : Asus P4U800-X, Čipset : Ali Uli 1633 M, Procesor : Intel Celeron D @ 2660 MHz, Chladič : Arcting Colling Super Ultra TC, Fyzická pamäť : 1536 MB (1 x 1024 DDR400, 1 x 512 DDR400), Grafická karta : Sparkle Geforce 7600 GS 512 MB, Pevný disk :Hitachi 80 GB, Jednotka DVD-RW : LG GSA H55L, Operačný systém : Microsoft Windows Seven Ultimate RC, DirectX : Verzia 11

NB::Samsung R510, Intel Celeron Dual Core @ 1830 MHz, 2 GB DDR2 ram, 160 GB Samsung HDD, Intel GMA 4500 MHD, 15,4 " displej
 [ Príspevkov: 3 ] 


Replace Text on web



Podobné témy

 Témy  Odpovede  Zobrazenia  Posledný príspevok 
V tomto fóre nie sú ďalšie neprečítané témy.

Replace text

v Frontend

5

581

28.05.2012 13:49

xxx9955

V tomto fóre nie sú ďalšie neprečítané témy.

Text Font pre web - stream

v Frontend

3

521

31.05.2012 23:39

shaggy

V tomto fóre nie sú ďalšie neprečítané témy.

Regex replace

v Ostatné

5

505

02.07.2021 14:53

MTK

V tomto fóre nie sú ďalšie neprečítané témy.

Replace Textu

v Backend

12

740

05.08.2009 9:52

p360t

V tomto fóre nie sú ďalšie neprečítané témy.

PHP replace help

v Backend

4

731

13.04.2008 19:31

Ded'leg

V tomto fóre nie sú ďalšie neprečítané témy.

string.replace na viac riadkoch nefunguje

v Frontend

11

802

22.03.2011 14:50

camo

V tomto fóre nie sú ďalšie neprečítané témy.

Invalid system disk replace the disk and press any key

v Windows

5

944

26.04.2008 6:20

mig07

V tomto fóre nie sú ďalšie neprečítané témy.

"Search and Replace" Shell skript

v Ostatné

1

585

13.06.2011 19:03

Ďuri

V tomto fóre nie sú ďalšie neprečítané témy.

Hľadáme programátora web stránok a web aplikácií

v Ponuka a dopyt práce

0

822

27.02.2013 11:51

artexe

V tomto fóre nie sú ďalšie neprečítané témy.

Web hosting control panel pre free web

v Hosting, servery a domény

1

1182

06.04.2019 8:05

rukitinc

V tomto fóre nie sú ďalšie neprečítané témy.

Hľadáme (1.) web dizajnéra a (2.) web kódera - na dlhodobú spoluprácu / práca z domu

v Ponuka a dopyt práce

0

893

15.01.2015 9:12

crystalgroup

V tomto fóre nie sú ďalšie neprečítané témy.

web kamera & web

v Video programy

4

977

29.12.2007 13:22

jablko05

V tomto fóre nie sú ďalšie neprečítané témy.

Text

v Frontend

3

988

15.10.2007 21:10

enorm

V tomto fóre nie sú ďalšie neprečítané témy.

Text

v Frontend

5

785

26.10.2009 17:23

hajtrak

V tomto fóre nie sú ďalšie neprečítané témy.

text

v Audio programy

5

676

24.07.2012 13:24

dangerous_123

V tomto fóre nie sú ďalšie neprečítané témy.

text

v Grafické programy

2

931

12.03.2008 19:49

Enermax



© 2005 - 2026 PCforum, edited by JanoF