Read in array from external array [JS file] [closed] - javascript

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 22 days ago.
This post was edited and submitted for review 22 days ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I want to modify this code, to instead read the - currenly commented - array from a "arrays.js"
<head><meta charset="UTF-8"><style>
div {text-align: left;}
h1 {font-size: 11px;font-family: Arial;}
button {width: 128px;height: 28px;background-color: white;color: black;}
{font-size: 11px;}
button:hover{background-color: white;}
</style></head><body>
<script src="arrays.js"></script>
<div><button onclick="generateQuote();">CurrListen</button><p id="quoteOutput"></div>
<script>
//const arrayOfQuotes = [
{'quote': '<a target="_blank" href="https://m.youtube.com/watch?v=Od4sH0vVFpI">Musique pour la tristesse de Xion - KHIII (Yoko Shimomura)</a>'},
{'quote': '<a target="_blank" href="https://youtube.com/watch?v=cqAawjQyieg">Kellys Lullaby - Another Code R - Satoshi Okubo</a>'},
{'quote': 'Nears Theme - Death Note OST III - Hideki Taniuchi'},
{'quote': 'Abandon Me - Chicory OST - Lena Raine'},
{'quote': '<a target="_blank" href="https://m.youtube.com/watch?v=xJMWAM--ePM">Vector to the Heavens - KH3582 OST - Yoko Shimomura</a>'},
{'quote': '<a target="_blank" href="https://youtube.com/watch?v=Yf6Eqze6sMM">Forgotten Legend - Gyakuten Saiban 4 OST - Toshihiko Horiyama</a>'},
{'quote': '<a target="_blank" href="https://youtube.com/watch?v=Y20l0tW9VfQ">Solitude - Amagi Brilliant Park - Shinkichi Mitsumune</a>'},
{'quote': '<a target="_blank" href="https://youtube.com/watch?v=FVSkRipU2oE">Girl of catching Theme - Speed Grapher OST I - Shinkichi Mitsumune</a>'},
{'quote': '<a target="_blank" href="https://youtube.com/watch?v=R7jhnVdLz50">Esperanto - RZero Physis OST - Luna Umegaki</a>'},
{'quote': '<a target="_blank" href="https://youtube.com/watch?v=yFabSBzC068">Ai wa kurayami no naka de - ZARD</a>'},
{'quote': '<a target="_blank" href="https://youtube.com/watch?v=XU8j5TGaX8g&list=PLJXkRwmABZWQxfi-uKuEgGrY31RUWRmvv&index=7">Tranc</a>'},
{'quote': '<a target="_blank" href="https://m.youtube.com/watch?v=oCF_leSNIfA&list=PL0bj_3nLaCVwfKoGJX8AeTJKYfGNgFq0D&index=18">Blue Indigo</a>'},
{'quote': '<a target="_blank" href="https://m.youtube.com/watch?v=PTKl17TXqyo&list=PLLiHaMFYDWBTFMLdgVBKUPxW2vs0WlAKL&index=1">Lily - Ender Lilies</a>'},
];
function generateQuote(){const random = Number.parseInt(Math.random()*arrayOfQuotes.length + 1);
document.querySelector('#quoteOutput').innerHTML = `\"${arrayOfQuotes[random].quote}\"`;}
</script>
</body>
I defined <script src="arrays.js"></script> beforehand,
but it fails to work.
What is needed to get this to function ?
More Declaration ?
A special new formatting ?

arrays.js
const arrayOfQuotes = [
// ...
];
window.arrayOfQuotes = arrayOfQuotes

Related

How to take an unformatted list and make it formatted for Javascript [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I have a very large list that I copied from a text file of about 180 items. The list, however, is not formatted to work in Javascript as it doesn't contain any commas. I'm very new to Javascript, so this maybe a very easy fix. Right now the list looks like this :
Bulbasaur
Ivysaur
Venusaur
Charmander
Charmeleon
Charizard
Squirtle
Wartortle
Blastoise
Caterpie
Metapod
Butterfree
Weedle
Kakuna
Beedrill
Pidgey
Pidgeotto
Pidgeot
Rattata
Raticate
Spearow
Fearow
Ekans
Arbok
Pikachu
Raichu
Sandshrew
Sandslash
Nidoran♀
Nidorina
Nidoqueen
Nidoran♂
Nidorino
Nidoking
Clefairy
Clefable
Vulpix
Ninetales
Jigglypuff
Wigglytuff
Zubat
Golbat
Oddish
Gloom
Vileplume
Paras
Parasect
Venonat
Venomoth
Diglett
Dugtrio
Meowth
Persian
Psyduck
Golduck
Mankey
Primeape
Growlithe
Arcanine
Poliwag
Poliwhirl
Poliwrath
Abra
Kadabra
Alakazam
Machop
Machoke
Machamp
Bellsprout
Weepinbell
Victreebel
Tentacool
Tentacruel
Geodude
Graveler
Golem
Ponyta
Rapidash
Slowpoke
Slowbro
Magnemite
Magneton
Farfetch'd
Doduo
Dodrio
Seel
Dewgong
Grimer
Muk
Shellder
Cloyster
Gastly
Haunter
Gengar
Onix
Drowzee
Hypno
Krabby
Kingler
Voltorb
Electrode
Exeggcute
Exeggutor
Cubone
Marowak
Hitmonlee
Hitmonchan
Lickitung
Koffing
Weezing
Rhyhorn
Rhydon
Chansey
Tangela
Kangaskhan
Horsea
Seadra
Goldeen
Seaking
Staryu
Starmie
Mr. Mime
Scyther
Jynx
Electabuzz
Magmar
Pinsir
Tauros
Magikarp
Gyarados
Lapras
Ditto
Eevee
Vaporeon
Jolteon
Flareon
Porygon
Omanyte
Omastar
Kabuto
Kabutops
Aerodactyl
Snorlax
Articuno
Zapdos
Moltres
Dratini
Dragonair
Dragonite
Mewtwo
Mew
How would I convert this into a working list or array in Javascript?
Here's one way, put it into a hidden element and parse it out. Since the list you show already has line breaks, you can't put it into a variable as is.
let list = document.querySelector('#pokemon').innerText.split("\n").join(",");
console.log(list);
#pokemon{
display:none;
}
<div id='pokemon'>
Bulbasaur
Ivysaur
Venusaur
Charmander
Charmeleon
Charizard
Squirtle
Wartortle
Blastoise
Caterpie
Metapod
Butterfree
Weedle
Kakuna
Beedrill
Pidgey
Pidgeotto
Pidgeot
Rattata
Raticate
Spearow
Fearow
Ekans
Arbok
Pikachu
Raichu
Sandshrew
Sandslash
Nidoran♀
Nidorina
Nidoqueen
Nidoran♂
Nidorino
Nidoking
Clefairy
Clefable
Vulpix
Ninetales
Jigglypuff
Wigglytuff
Zubat
Golbat
Oddish
Gloom
Vileplume
Paras
Parasect
Venonat
Venomoth
Diglett
Dugtrio
Meowth
Persian
Psyduck
Golduck
Mankey
Primeape
Growlithe
Arcanine
Poliwag
Poliwhirl
Poliwrath
Abra
Kadabra
Alakazam
Machop
Machoke
Machamp
Bellsprout
Weepinbell
Victreebel
Tentacool
Tentacruel
Geodude
Graveler
Golem
Ponyta
Rapidash
Slowpoke
Slowbro
Magnemite
Magneton
Farfetch'd
Doduo
Dodrio
Seel
Dewgong
Grimer
Muk
Shellder
Cloyster
Gastly
Haunter
Gengar
Onix
Drowzee
Hypno
Krabby
Kingler
Voltorb
Electrode
Exeggcute
Exeggutor
Cubone
Marowak
Hitmonlee
Hitmonchan
Lickitung
Koffing
Weezing
Rhyhorn
Rhydon
Chansey
Tangela
Kangaskhan
Horsea
Seadra
Goldeen
Seaking
Staryu
Starmie
Mr. Mime
Scyther
Jynx
Electabuzz
Magmar
Pinsir
Tauros
Magikarp
Gyarados
Lapras
Ditto
Eevee
Vaporeon
Jolteon
Flareon
Porygon
Omanyte
Omastar
Kabuto
Kabutops
Aerodactyl
Snorlax
Articuno
Zapdos
Moltres
Dratini
Dragonair
Dragonite
Mewtwo
Mew
</div>
`Bulbasaur
Ivysaur
Venusaur
Charmander
Charmeleon
Charizard
Squirtle`.split('\n').join(',');

How do I change the content of figcaption using javascript? [duplicate]

This question already has answers here:
Double quote in JavaScript string
(4 answers)
Closed 2 years ago.
<button onclick="changefigure()">2011</button>
<figure>
<img id="Image" src="NT_Naplan_Reading_Results_2017.png"/>
<figcaption id="caption"><em>Fig 2</em>Percent of children above national minimum standard in
reading in 2017 for Year 3, 5, 7 and 9 for Non-Indigenous and Indigenous children in the
Northern Territory. Data Source NAPLAN results</figcaption>
</figure>
<script>
function changefigure()
{
var x = document.getElementById("Image");
var y = document.getElementById("caption")
x.src = 'NT_Naplan_Reading_Results_2011.png'
//y = "<em>Fig 1</em>Percent of children above national minimum standard in reading in
2017 for Year 3, 5, 7 and 9 for Non-Indigenous and Indigenous children in the Northern
Territory. Data Source NAPLAN results"
}
</script>
So I can't seem to be able to change the figcaption. I've tried using y.innerHTML and y.innertext but both of them dont seem to work. Any tips?
So i found out what's wrong with my code. Instead of using " use ' for it to for.
E.G.
<script>
function changefigure()
{
var x = document.getElementById("Image");
var y = document.getElementById("caption")
x.src = 'NT_Naplan_Reading_Results_2011.png'
y.innerHTML = '<em>Fig 1</em>Percent of children above national minimum
standard in reading in 2017 for Year 3, 5, 7 and 9 for Non-Indigenous and
Indigenous children in the Northern Territory. Data Source <a href="">NAPLAN
results</a>'
}
</script>

.save() does not change the value of a field , django [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I am trying to implement a notification system. When the user clicks onto one of the notification from the drop down box , i will use a AJAX Post request to modify the boolean field to indicate that that particular instance of the Notification has been read before.
here is my code:
This is my HTML template:
<ul class="dropdown-menu dropdown-menu-right myDropDown">
{%for noti in notifications%}
{{noti}}
<li>
<a href="#" class="top-text-block" id="{{noti.id}}" onClick="return booleanchanger(this.id);">
<div class="top-text-heading">{{noti.object_type}}</div>
<p class = 'text-muted'><small>{{noti.time}}</small>></p>
<div class="top-text-light">{{noti.message}}</div>
</a>
</li>
{%endfor%}
</ul>
This is my ajax call :
function booleanchanger(clicked_id){
var a = clicked_id
$.ajax({
url : "{% url 'read-notification' %}",
type : "POST",
data : {
'csrfmiddlewaretoken' : "{{ csrf_token }}",
'pk' : a
},
success : function(result) {
}
});
This is my notifications model:
class Notifications(models.Model):
time = models.DateTimeField(auto_now=True)
target = models.ForeignKey(User , on_delete=models.CASCADE)
message = models.TextField()
object_type = models.CharField(max_length=100)
object_url = models.CharField(max_length=500,default = 'test')
is_read = models.BooleanField(default=False)
This is my view that handles the ajax request:
def ReadNotificationView(request):
if request.method=='POST' and request.is_ajax():
pk = request.POST.get('pk',False)
obj = Notifications.objects.get(pk=pk)
obj.if_read = True
obj.save()
print(obj.if_read)
return JsonResponse({'status':'Success', 'is_read': 'changed'})
else:
return JsonResponse({'status':'Fail', 'is_read':'not changed'})
this is the url.py:
path('notification/update/' , views.ReadNotificationView , name = 'read-notification')
print(obj.if_read) from within my view returns me this:
True
However , going into the django admin page and checking the status of the is_read field shows that the code does not work . Does anyone have a solution for this ? I will greatly appreciate it!
Typo. In model you got is_read in view if_read

Found this malicious javascript in a file...what does it do? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I was editing a PHP file when I found this javascript code linked to an external js file at the end of my file:
!function(n,e,t){function r(t,i){if(!e[t]){if(!n[t]){var a="function"==typeof __nr_require&&__nr_require;if(!i&&a)return a(t,!0);if(o)return o(t,!0);throw new Error("Cannot find module '"+t+"'")}var s=e[t]={exports:{}};n[t][0].call(s.exports,function(e){var o=n[t][1][e];return r(o||e)},s,s.exports)}return e[t].exports}for(var o="function"==typeof __nr_require&&__nr_require,i=0;i<t.length;i++)r(t[i]);return r}({1:[function(n,e,t){e.exports=function(n,e){return"addEventListener"in window?addEventListener(n,e,!1):"attachEvent"in window?attachEvent("on"+n,e):void 0}},{}],2:[function(n,e,t){function r(n,e,t,r){p("bstAgg",[n,e,t,r]),l[n]||(l[n]={});var i=l[n][e];return i||(i=l[n][e]={params:t||{}}),i.metrics=o(r,i.metrics),i}function o(n,e){return e||(e={count:0}),e.count+=1,c(n,function(n,t){e[n]=i(t,e[n])}),e}function i(n,e){return e?(e&&!e.c&&(e={t:e.t,min:e.t,max:e.t,sos:e.t*e.t,c:1}),e.c+=1,e.t+=n,e.sos+=n*n,n>e.max&&(e.max=n),n<e.min&&(e.min=n),e):{t:n}}function a(n,e){return e?l[n]&&l[n][e]:l[n]}function s(n){for(var e={},t="",r=!1,o=0;o<n.length;o++)t=n[o],e[t]=u(l[t]),e[t].length&&(r=!0),delete l[t];return r?e:null}function u(n){return"object"!=typeof n?[]:c(n,f)}function f(n,e){return e}var c=n(30),p=n("handle"),l={};e.exports={store:r,take:s,get:a}},{}],3:[function(n,e,t){function r(n,e,t){"string"==typeof e&&("/"!==e.charAt(0)&&(e="/"+e),d.customTransaction=(t||"http://custom.transaction")+e)}function o(n,e){var t=e||n;f.store("cm","finished",{name:"finished"},{time:t-d.offset}),i(n,{name:"finished",start:t,origin:"nr"}),m("api-addPageAction",[t,"finished"])}function i(n,e){if(e&&"object"==typeof e&&e.name&&e.start){var t={n:e.name,s:e.start-d.offset,e:(e.end||e.start)-d.offset,o:e.origin||"",t:"api"};m("bstApi",[t])}}function a(n,e,t,r,o,i,a){if(e=window.encodeURIComponent(e),v+=1,d.info.beacon){var s=d.proto+d.info.beacon+"/1/"+d.info.licenseKey;s+="?a="+d.info.applicationID+"&",s+="t="+e+"&",s+="qt="+~~t+"&",s+="ap="+~~r+"&",s+="be="+~~o+"&",s+="dc="+~~i+"&",s+="fe="+~~a+"&",s+="c="+v,p.img(s)}}var s=n(14),u=n(9),f=n(2),c=n(16),p=n(8),l=n(30),d=n("loader"),m=n("handle"),v=0;u.on("jserrors",function(){return{body:f.take(["cm"])}});var h={finished:c(o),setPageViewName:r,addToTrace:i,inlineHit:a};l(h,function(n,e){s("api-"+n,e,"api")})},{}],4:[function(n,e,t){var r=/#|\?/,o=/#.*|$/;e.exports=function(n,e){var t=n.split(r)[0];return e?t+o.exec(n)[0]:t}},{}],5:[function(n,e,t){function r(n,e){var t=n[1];i(e[t],function(e,t){var r=n[0],o=t[0];if(o===r){var i=t[1],a=n[3],s=n[2];i.apply(a,s)}})}var o=n("ee"),i=n(30),a=n(14).handlers;e.exports=function(n){var e=o.backlog[n],t=a[n];if(t){for(var s=0;e&&s<e.length;++s)r(e[s],t);i(t,function(n,e){i(e,function(e,t){t[0].on(n,t[1])})})}delete a[n],o.backlog[n]=null}},{}],6:[function(n,e,t){function r(n){return c[n]}function o(n){return null===n||void 0===n?"null":encodeURIComponent(n).replace(l,r)}function i(n,e){for(var t=0,r=0;r<n.length;r++)if(t+=n[r].length,t>e)return n.slice(0,r).join("");return n.join("")}function a(n,e){var t=0,r="";return u(n,function(n,i){var a,s,u=[];if("string"==typeof i)a="&"+n+"="+o(i),t+=a.length,r+=a;else if(i.length){for(t+=9,s=0;s<i.length&&(a=o(f(i[s])),t+=a.length,!("undefined"!=typeof e&&t>=e));s++)u.push(a);r+="&"+n+"=%5B"+u.join(",")+"%5D"}}),r}function s(n,e){return e&&"string"==typeof e?"&"+n+"="+o(e):""}var u=n(30),f=n(19),c={"%2C":",","%3A":":","%2F":"/","%40":"#","%24":"$","%3B":";"},p=u(c,function(n){return n}),l=new RegExp(p.join("|"),"g");e.exports={obj:a,fromArray:i,qs:o,param:s}},{}],7:[function(n,e,t){var r=n(30),o=n("ee"),i=n(5);e.exports=function(n){n&&"object"==typeof n&&(r(n,function(n,e){e&&!a[n]&&(o.emit("feat-"+n,[]),a[n]=!0)}),i("feature"))};var a=e.exports.active={}},{}],8:[function(n,e,t){var r=e.exports={};r.jsonp=function(n,e){var t=document.createElement("script");t.type="text/javascript",t.src=n+"&jsonp="+e;var r=document.getElementsByTagName("script")[0];return r.parentNode.insertBefore(t,r),t},r.xhr=function(n,e){var t=new XMLHttpRequest;return t.open("POST",n,!0),"withCredentials"in t&&(t.withCredentials=!0),t.setRequestHeader("content-type","text/plain"),t.send(e),t},r.img=function(n){var e=new Image;return e.src=n,e},r.beacon=function(n,e){return navigator.sendBeacon(n,e)}},{}],9:[function(n,e,t){function r(n){if(n.info.beacon){n.info.queueTime&&b.store("measures","qt",{value:n.info.queueTime}),n.info.applicationTime&&b.store("measures","ap",{value:n.info.applicationTime}),k.measure("be","starttime","firstbyte"),k.measure("fe","firstbyte","onload"),k.measure("dc","firstbyte","domContent");var e=b.get("measures"),t=v(e,function(n,e){return"&"+n+"="+e.params.value}).join("");if(t){var r="1",o=[l(n)];if(o.push(t),o.push(g.param("tt",n.info.ttGuid)),o.push(g.param("us",n.info.user)),o.push(g.param("ac",n.info.account)),o.push(g.param("pr",n.info.product)),o.push(g.param("af",v(n.features,function(n){return n}).join(","))),window.performance&&"undefined"!=typeof window.performance.timing){var i={timing:h.addPT(window.performance.timing,{}),navigation:h.addPN(window.performance.navigation,{})};o.push(g.param("perf",y(i)))}o.push(g.param("xx",n.info.extra)),o.push(g.param("ua",n.info.userAttributes)),o.push(g.param("at",n.info.atts));var a=y(n.info.jsAttributes);o.push(g.param("ja","{}"===a?null:a));var s=g.fromArray(o,n.maxBytes);w.jsonp(n.proto+n.info.beacon+"/"+r+"/"+n.info.licenseKey+s,T)}}}function o(n){var e=v(A,function(e){return a(e,n,{unload:!0})});return x(e,i)}function i(n,e){return n||e}function a(n,e,t){return u(e,n,s(n),t||{})}function s(n){for(var e=d({}),t=d({}),r=A[n]||[],o=0;o<r.length;o++){var i=r[o]();i.body&&v(i.body,e),i.qs&&v(i.qs,t)}return{body:e(),qs:t()}}function u(n,e,t,r){if(!n.info.errorBeacon||!t.body)return!1;var o="https://"+n.info.errorBeacon+"/"+e+"/1/"+n.info.licenseKey+l(n);t.qs&&(o+=g.obj(t.qs,n.maxBytes));var i,a,s;switch(e){case"jserrors":a=!1,i=q?w.beacon:w.img;break;default:if(r.needResponse)a=!0,i=w.xhr;else if(r.unload)a=q,i=q?w.beacon:w.img;else if(q)a=!0,i=w.beacon;else if(L)a=!0,i=w.xhr;else{if("events"!==e)return!1;i=w.img}}return a&&"events"===e?s=t.body.e:a?s=y(t.body):o+=g.obj(t.body,n.maxBytes),i(o,s)}function f(n){if(n&&n.info&&n.info.errorBeacon&&n.ieVersion){var e="https://"+n.info.errorBeacon+"/jserrors/ping/"+n.info.licenseKey+l(n);w.img(e)}}function c(n){return n.info.transactionName?g.param("to",n.info.transactionName):g.param("t",n.info.tNamePlain||"Unnamed Transaction")}function p(n,e){var t=A[n]||(A[n]=[]);t.push(e)}function l(n){return["?a="+n.info.applicationID,g.param("sa",n.info.sa?""+n.info.sa:""),g.param("v",S),c(n),g.param("ct",n.customTransaction),"&rst="+((new Date).getTime()-n.offset),g.param("ref",E(n.origin))].join("")}function d(n){var e=!1;return function(t,r){return r&&r.length&&(n[t]=r,e=!0),e?n:void 0}}var m=n(16),v=n(30),h=n(13),g=n(6),y=n(19),w=n(8),x=n(32),b=n(2),k=n(18),j=n("loader"),E=n(4),S="943.9bd99bf",T="NREUM.setToken",A={},q=!!navigator.sendBeacon;n(10);var L=j.xhrWrappable&&(j.ieVersion>9||0===j.ieVersion);e.exports={sendBeacon:m(r),sendFinal:o,pingErrors:f,sendX:a,on:p,xhrUsable:L}},{}],10:[function(n,e,t){var r=n("loader"),o=document.createElement("div");o.innerHTML="<!--[if lte IE 6]><div></div><![endif]--><!--[if lte IE 7]><div></div><![endif]--><!--[if lte IE 8]><div></div><![endif]--><!--[if lte IE 9]><div></div><![endif]-->";var i=o.getElementsByTagName("div").length;4===i?r.ieVersion=6:3===i?r.ieVersion=7:2===i?r.ieVersion=8:1===i?r.ieVersion=9:r.ieVersion=0,e.exports=r.ieVersion},{}],11:[function(n,e,t){function r(n){f.sendFinal(l,!1),a.navCookie&&(document.cookie="NREUM=s="+Number(new Date)+"&r="+o(document.location.href)+"&p="+o(document.referrer)+"; path=/")}var o=n(15),i=n(1),a=n(17),s=n(18),u=n(16),f=n(9),c=n(14),p=n(7),l=n("loader"),d=n(29),m=n(5);n(3);var v="undefined"!=typeof window.NREUM.autorun?window.NREUM.autorun:!0;window.NREUM.setToken=p,6===n(10)?l.maxBytes=2e3:l.maxBytes=3e4;var h=u(r);!d||navigator.sendBeacon?i("pagehide",h):i("beforeunload",h),i("unload",h),c("mark",s.mark,"api"),s.mark("done"),m("api"),v&&f.sendBeacon(l)},{}],12:[function(n,e,t){e.exports=function(n,e){setTimeout(function t(){try{n()}finally{setTimeout(t,e)}},e)}},{}],13:[function(n,e,t){function r(n,e){var t=n.navigationStart;return e.of=t,i(n.navigationStart,t,e,"n"),i(n.unloadEventStart,t,e,"u"),i(n.unloadEventEnd,t,e,"ue"),i(n.domLoading,t,e,"dl"),i(n.domInteractive,t,e,"di"),i(n.domContentLoadedEventStart,t,e,"ds"),i(n.domContentLoadedEventEnd,t,e,"de"),i(n.domComplete,t,e,"dc"),i(n.loadEventStart,t,e,"l"),i(n.loadEventEnd,t,e,"le"),i(n.redirectStart,t,e,"r"),i(n.redirectEnd,t,e,"re"),i(n.fetchStart,t,e,"f"),i(n.domainLookupStart,t,e,"dn"),i(n.domainLookupEnd,t,e,"dne"),i(n.connectStart,t,e,"c"),i(n.connectEnd,t,e,"ce"),i(n.secureConnectionStart,t,e,"s"),i(n.requestStart,t,e,"rq"),i(n.responseStart,t,e,"rp"),i(n.responseEnd,t,e,"rpe"),e}function o(n,e){return i(n.type,0,e,"ty"),i(n.redirectCount,0,e,"rc"),e}function i(n,e,t,r){"number"==typeof n&&n>0&&(t[r]=Math.round(n-e))}e.exports={addPT:r,addPN:o}},{}],14:[function(n,e,t){function r(n,e,t,r){o(r||i,n,e,t)}function o(n,e,t,r){r||(r="feature"),n||(n=i);var o=a[r]=a[r]||{},s=o[e]=o[e]||[];s.push([n,t])}var i=n("handle").ee;e.exports=r,r.on=o;var a=r.handlers={}},{}],15:[function(n,e,t){function r(n){var e,t=0;for(e=0;e<n.length;e++)t+=(e+1)*n.charCodeAt(e);return Math.abs(t)}e.exports=r},{}],16:[function(n,e,t){function r(n){var e,t=!1;return function(){return t?e:(t=!0,e=n.apply(this,o(arguments)))}}var o=n(31);e.exports=r},{}],17:[function(n,e,t){function r(){var n=o()||i();n&&(s.mark("starttime",n),u.offset=n)}function o(){return f&&9>f?void 0:"undefined"!=typeof window.performance&&window.performance.timing&&"undefined"!=typeof window.performance.timing.navigationStart?(e.exports.navCookie=!1,window.performance.timing.navigationStart):void 0}function i(){for(var n=document.cookie.split(" "),e=0;e<n.length;e++)if(0===n[e].indexOf("NREUM=")){for(var t,r,o,i,s=n[e].substring("NREUM=".length).split("&"),u=0;u<s.length;u++)0===s[u].indexOf("s=")?o=s[u].substring(2):0===s[u].indexOf("p=")?(r=s[u].substring(2),";"===r.charAt(r.length-1)&&(r=r.substr(0,r.length-1))):0===s[u].indexOf("r=")&&(t=s[u].substring(2),";"===t.charAt(t.length-1)&&(t=t.substr(0,t.length-1)));if(t){var f=a(document.referrer);i=f==t,i||(i=a(document.location.href)==t&&f==r)}if(i&&o){var c=(new Date).getTime();if(c-o>6e4)return;return o}}}var a=n(15),s=n(18),u=n("loader"),f=n(29);e.exports={navCookie:!0},r()},{}],18:[function(n,e,t){function r(n,e){"undefined"==typeof e&&(e=(new Date).getTime()),a[n]=e}function o(n,e,t){var r=a[e],o=a[t];"undefined"!=typeof r&&"undefined"!=typeof o&&i.store("measures",n,{value:o-r})}var i=n(2),a={};e.exports={mark:r,measure:o}},{}],19:[function(n,e,t){function r(n){try{return i("",{"":n})}catch(e){try{s.emit("internal-error",[e])}catch(t){}}}function o(n){return u.lastIndex=0,u.test(n)?'"'+n.replace(u,function(n){var e=f[n];return"string"==typeof e?e:"\\u"+("0000"+n.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+n+'"'}function i(n,e){var t=e[n];switch(typeof t){case"string":return o(t);case"number":return isFinite(t)?String(t):"null";case"boolean":return String(t);case"object":if(!t)return"null";var r=[];if("[object Array]"===Object.prototype.toString.apply(t)){for(var s=t.length,u=0;s>u;u+=1)r[u]=i(u,t)||"null";return 0===r.length?"[]":"["+r.join(",")+"]"}return a(t,function(n){var e=i(n,t);e&&r.push(o(n)+":"+e)}),0===r.length?"{}":"{"+r.join(",")+"}"}}var a=n(30),s=n("ee"),u=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,f={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"};e.exports=r},{}],20:[function(n,e,t){function r(n){if(n){var e=n.match(o);return e?e[1]:void 0}}var o=/([a-z0-9]+)$/i;e.exports=r},{}],21:[function(n,e,t){function r(n){var e=null;try{if(e=p(n))return e}catch(t){if(h)throw t}try{if(e=o(n))return e}catch(t){if(h)throw t}try{if(e=l(n))return e}catch(t){if(h)throw t}try{if(e=s(n))return e}catch(t){if(h)throw t}try{if(e=u(n))return e}catch(t){if(h)throw t}return{mode:"failed",stackString:"",frames:[]}}function o(n){if(!n.stack)return null;var e=d(n.stack.split("\n"),i,{frames:[],stackLines:[],wrapperSeen:!1});return e.frames.length?{mode:"stack",name:n.name||f(n),message:n.message,stackString:m(e.stackLines),frames:e.frames}:null}function i(n,e){var t=a(e);return t?(c(t.func)?n.wrapperSeen=!0:n.stackLines.push(e),n.wrapperSeen||n.frames.push(t),n):(n.stackLines.push(e),n)}function a(n){var e=n.match(w);return e||(e=n.match(y)),e?{url:e[2],func:"Anonymous function"!==e[1]&&e[1]||null,line:+e[3],column:e[4]?+e[4]:null}:n.match(x)||n.match(b)||"anonymous"===n?{func:"evaluated code"}:void 0}function s(n){if(!("line"in n))return null;var e=n.name||f(n);if(!n.sourceURL)return{mode:"sourceline",name:e,message:n.message,stackString:f(n)+": "+n.message+"\n in evaluated code",frames:[{func:"evaluated code"}]};var t=e+": "+n.message+"\n at "+n.sourceURL;return n.line&&(t+=":"+n.line,n.column&&(t+=":"+n.column)),{mode:"sourceline",name:e,message:n.message,stackString:t,frames:[{url:n.sourceURL,line:n.line,column:n.column}]}}function u(n){var e=n.name||f(n);return e?{mode:"nameonly",name:e,message:n.message,stackString:e+": "+n.message,frames:[]}:null}function f(n){var e=g.exec(String(n.constructor));return e&&e.length>1?e[1]:"unknown"}function c(n){return n&&n.indexOf("nrWrapper")>=0}function p(n){for(var e,t=n.stacktrace,r=/ line (\d+), column (\d+) in (?:<anonymous function: ([^>]+)>|([^\)]+))\(.*\) in (.*):\s*$/i,o=t.split("\n"),i=[],a=[],s=!1,u=0,p=o.length;p>u;u+=2)if(e=r.exec(o[u])){var l={line:+e[1],column:+e[2],func:e[3]||e[4],url:e[5]};c(l.func)?s=!0:a.push(o[u]),s||i.push(l)}else a.push(o[u]);return i.length?{mode:"stacktrace",name:n.name||f(n),message:n.message,stackString:m(a),frames:i}:null}function l(n){var e=n.message.split("\n");if(e.length<4)return null;var t,r,o,i=/^\s*Line (\d+) of linked script ((?:file|http|https)\S+)(?:: in function (\S+))?\s*$/i,a=/^\s*Line (\d+) of inline#(\d+) script in ((?:file|http|https)\S+)(?:: in function (\S+))?\s*$/i,s=/^\s*Line (\d+) of function script\s*$/i,u=[],p=[],l=document.getElementsByTagName("script"),d=[],h=!1;for(r in l)v.call(l,r)&&!l[r].src&&d.push(l[r]);for(r=2,o=e.length;o>r;r+=2){var g=null;if(t=i.exec(e[r]))g={url:t[2],func:t[3],line:+t[1]};else if(t=a.exec(e[r]))g={url:t[3],func:t[4]};else if(t=s.exec(e[r])){var y=window.location.href.replace(/#.*$/,""),w=t[1];g={url:y,line:w,func:""}}g&&(c(g.func)?h=!0:p.push(e[r]),h||u.push(g))}return u.length?{mode:"multiline",name:n.name||f(n),message:e[0],stackString:m(p),frames:u}:null}var d=n(32),m=n(22),v=Object.prototype.hasOwnProperty,h=!1,g=/function (.+?)\s*\(/,y=/^\s*at (?:((?:\[object object\])?(?:[^(]*\([^)]*\))*[^()]*(?: \[as \S+\])?) )?\(?((?:file|http|https|chrome-extension):.*?)?:(\d+)(?::(\d+))?\)?\s*$/i,w=/^\s*(?:(\S*)(?:\(.*?\))?#)?((?:file|http|https|chrome|safari-extension).*?):(\d+)(?::(\d+))?\s*$/i,x=/^\s*at .+ \(eval at \S+ \((?:(?:file|http|https):[^)]+)?\)(?:, [^:]*:\d+:\d+)?\)$/i,b=/^\s*at Function code \(Function code:\d+:\d+\)\s*/i;e.exports=r},{}],22:[function(n,e,t){var r=/^\n+|\n+$/g;e.exports=function(n){var e;if(n.length>100){var t=n.length-100;e=n.slice(0,50).join("\n"),e+="\n< ...truncated "+t+" lines... >\n",e+=n.slice(-50).join("\n")}else e=n.join("\n");return e.replace(r,"")}},{}],23:[function(n,e,t){function r(n){return l(n.exceptionClass)^n.stackHash}function o(n,e){if("string"!=typeof n)return"";var t=c(n);return t===e?"<inline>":t}function i(n,e){for(var t="",r=0;r<n.frames.length;r++){var o=n.frames[r],i=f(o.func);t&&(t+="\n"),i&&(t+=i+"#"),"string"==typeof o.url&&(t+=o.url),o.line&&(t+=":"+o.line)}return t}function a(n){for(var e=c(d.origin),t=0;t<n.frames.length;t++){var r=n.frames[t],i=r.url,a=o(i,e);a&&a!==r.url&&(r.url=a,n.stackString=n.stackString.split(i).join(a))}return n}function s(n,e,t){e||(e=(new Date).getTime());var o=a(p(n)),s=i(o),f={stackHash:l(s),exceptionClass:o.name,request_uri:window.location.pathname};o.message&&(f.message=""+o.message),v[f.stackHash]?f.browser_stack_hash=l(o.stackString):(v[f.stackHash]=!0,f.stack_trace=o.stackString);var c=r(f);h[c]||(f.pageview=1,h[c]=!0),u.store(t?"ierr":"err",c,f,{time:e-d.offset})}var u=n(2),f=n(20),c=n(4),p=n(21),l=n(24),d=n("loader"),m=n("ee"),v={},h={},g=n(14),y=n(9),w=n(12);if(n(17),d.features.err){var x=!1;y.on("jserrors",function(){var n=u.take(["err","ierr"]),e={body:n};return n&&n.err&&n.err.length&&!x&&(e.qs={pve:"1"},x=!0),e}),y.pingErrors(d),w(function(){var n=y.sendX("jserrors",d);n||y.pingErrors(d)},6e4),m.on("feat-err",function(){g("err",s),g("ierr",s)}),e.exports=s}},{}],24:[function(n,e,t){function r(n){var e,t=0;if(!n||!n.length)return t;for(var r=0;r<n.length;r++)e=n.charCodeAt(r),t=(t<<5)-t+e,t=0|t;return t}e.exports=r},{}],25:[function(n,e,t){function r(n,e,t){function r(n,e){t[n]||(t[n]=e)}if(!(g.length>=h)){e||(e=""),t&&"object"==typeof t||(t={});var o,a;"undefined"!=typeof window&&window.document&&window.document.documentElement&&(o=window.document.documentElement.clientWidth,a=window.document.documentElement.clientHeight);var c={timestamp:n,timeSinceLoad:(n-s.offset)/1e3,browserWidth:o,browserHeight:a,referrerUrl:i,currentUrl:l(""+location),pageUrl:l(s.origin),eventType:"PageAction"};u(y,r),u(c,r),t.actionName=e,u(t,function(n,e){e&&"object"==typeof e&&(t[n]=f(e))}),g.push(t)}}function o(n,e,t){y[e]=t}var i,a=n("ee"),s=n("loader"),u=n(30),f=n(19),c=n(14),p=n(9),l=n(4),d=n(12),m=120,v=10,h=m*v/60,g=[],y=s.info.jsAttributes={};document.referrer&&(i=l(document.referrer)),c("api-setCustomAttribute",o,"api"),a.on("feat-ins",function(){c("api-addPageAction",r),p.on("ins",function(){return{qs:{ua:s.info.userAttributes,at:s.info.atts},body:{ins:g.splice(0)}}}),d(function(){p.sendX("ins",s)},1e3*v),p.sendX("ins",s)})},{}],26:[function(n,e,t){function r(n){var e,t,r,o=Date.now();for(e in n)t=n[e],"number"==typeof t&&t>0&&o>t&&(r=n[e]-w.offset,p({n:e,s:r,e:r,o:"document",t:"timing"}))}function o(n,e,t,r){var o="timer";"requestAnimationFrame"===r&&(o=r);var i={n:r,s:e-w.offset,e:t-w.offset,o:"window",t:o};p(i)}function i(n,e,t,r){if(n.type in L)return!1;var o={n:a(n.type),s:t-w.offset,e:r-w.offset,o:s(n.target,e),t:"event"};p(o)}function a(n){var e=n;return k(C,function(t,r){n in r&&(e=t)}),e}function s(n,e){var t="unknown";if(n&&n instanceof XMLHttpRequest){var r=R.context(n).params;t=r.status+" "+r.method+": "+r.host+r.pathname}else n&&"string"==typeof n.tagName&&(t=n.tagName.toLowerCase(),n.id&&(t+="#"+n.id),n.className&&(t+="."+S(n.classList).join(".")));return"unknown"===t&&(e===document?t="document":e===window?t="window":e instanceof FileReader&&(t="FileReader")),t}function u(n,e,t){var r={n:"history.pushState",s:t-w.offset,e:t-w.offset,o:n,t:e};p(r)}function f(n){n.forEach(function(n){var e=T(n.name),t={n:n.initiatorType,s:0|n.fetchStart,e:0|n.responseEnd,o:e.protocol+"://"+e.hostname+":"+e.port+e.pathname,t:n.entryType};t.s<U||(U=t.s,p(t))})}function c(n,e,t,r){var o=null;"err"===n?o={n:"error",s:r.time,e:r.time,o:t.message,t:t.stackHash}:"xhr"===n&&(o={n:"Ajax",s:r.time,e:r.time+r.duration,o:t.status+" "+t.method+": "+t.host+t.pathname,t:"ajax"}),o&&p(o)}function p(n){var e=B[n.n];e||(e=B[n.n]=[]),e.push(n)}function l(n){var e=!0;return function(){return e||q?(e=!1,n()):{}}}function d(){f(window.performance.getEntriesByType("resource"));var n=j(k(B,function(n,e){return n in N?j(k(j(e.sort(m),v(n),{}),h),g,[]):e}),g,[]);if(0===n.length)return{};B={};var e={qs:{st:""+w.offset,ptid:q},body:{res:n}};if(!q){e.qs.ua=w.info.userAttributes,e.qs.at=w.info.atts;var t=E(w.info.jsAttributes);e.qs.ja="{}"===t?null:t}return e}function m(n,e){return n.s-e.s}function v(n){var e=N[n][0],t=N[n][1],r={};return function(o,i){var a=o[i.o];a||(a=o[i.o]=[]);var s=r[i.o];return"scrolling"!==n||y(i)?s&&i.s-s.s<t&&s.e>i.s-e?s.e=i.e:(r[i.o]=i,a.push(i)):(r[i.o]=null,i.n="scroll",a.push(i)),o}}function h(n,e){return e}function g(n,e){return n.concat(e)}function y(n){var e=4;return!!(n&&"number"==typeof n.e&&"number"==typeof n.s&&n.e-n.s<e)}var w=n("loader"),x=n(14),b=n(9),k=n(30),j=n(32),E=n(19),S=n(31),T=n(28),A=n(12);if(b.xhrUsable){var q="",L={mouseup:!0,mousedown:!0},N={typing:[1e3,2e3],scrolling:[100,1e3],mousing:[1e3,2e3],touching:[1e3,2e3]},C={typing:{keydown:!0,keyup:!0,keypress:!0},mousing:{mousemove:!0,mouseenter:!0,mouseleave:!0,mouseover:!0,mouseout:!0},scrolling:{scroll:!0},touching:{touchstart:!0,touchmove:!0,touchend:!0,touchcancel:!0,touchenter:!0,touchleave:!0}},B={},R=n("ee");if(e.exports={_takeSTNs:d},n(17),w.features.stn){R.on("feat-stn",function(){r(window.performance.timing),b.on("resources",l(d));var n=b.sendX("resources",w,{needResponse:!0});n.addEventListener("load",function(){q=this.responseText},!1),x("bst",i),x("bstTimer",o),x("bstResource",f),x("bstHist",u),x("bstAgg",c),x("bstApi",p),A(function(){var n=0;return Date.now()-w.offset>9e5?void(B={}):(k(B,function(e,t){t&&t.length&&(n+=t.length)}),n>30&&b.sendX("resources",w),void(n>1e3&&(B={})))},1e4)});var U=0}}},{}],27:[function(n,e,t){function r(n,e,t){e.time=t-u.offset,n.cat?o.store("xhr",s([n.status,n.cat]),n,e):o.store("xhr",s([n.status,n.host,n.pathname]),n,e)}var o=n(2),i=n(14),a=n(9),s=n(19),u=n("loader"),f=n("ee");u.features.xhr&&(a.on("jserrors",function(){return{body:o.take(["xhr"])}}),f.on("feat-err",function(){i("xhr",r)}),e.exports=r)},{}],28:[function(n,e,t){e.exports=function(n){var e=document.createElement("a"),t=window.location,r={};e.href=n,r.port=e.port;var o=e.href.split("://");!r.port&&o[1]&&(r.port=o[1].split("/")[0].split("#").pop().split(":")[1]),r.port&&"0"!==r.port||(r.port="https"===o[0]?"443":"80"),r.hostname=e.hostname||t.hostname,r.pathname=e.pathname,r.protocol=o[0],"/"!==r.pathname.charAt(0)&&(r.pathname="/"+r.pathname);var i=!e.protocol||":"===e.protocol||e.protocol===t.protocol,a=e.hostname===document.domain&&e.port===t.port;return r.sameOrigin=i&&(!e.hostname||a),r}},{}],29:[function(n,e,t){var r=0,o=navigator.userAgent.match(/Firefox[\/\s](\d+\.\d+)/);o&&(r=+o[1]),e.exports=r},{}],30:[function(n,e,t){function r(n,e){var t=[],r="",i=0;for(r in n)o.call(n,r)&&(t[i]=e(r,n[r]),i+=1);return t}var o=Object.prototype.hasOwnProperty;e.exports=r},{}],31:[function(n,e,t){function r(n,e,t){e||(e=0),"undefined"==typeof t&&(t=n?n.length:0);for(var r=-1,o=t-e||0,i=Array(0>o?0:o);++r<o;)i[r]=n[e+r];return i}e.exports=r},{}],32:[function(n,e,t){function r(n,e,t){var r=0;for("undefined"==typeof t&&(t=n[0],r=1),r;r<n.length;r++)t=e(t,n[r]);return t}e.exports=r},{}]},{},[23,27,26,25,11]);
This definitely seems malicious but I don't know what it is doing. Can anyone please tell me what this piece of code does?
This code looks like a normal part of New Relic's application performance analytics. It doesn't appear to be malicious.

javascript - replace from A to B [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I'm trying to make a chrome extension to replace comments of known trolls in a forum by silence.
is there a way to tell .replace to replace text from a startpoint to an endpoint?
i.e.: replace text starting with 'Name' until 'end of post' by ""
thanks in advance
edit:
to meet the comments:
walk(document.body);
function walk(node)
{
var child, next;
switch ( node.nodeType )
{
case 1: // Element
case 9: // Document
case 11: // Document fragment
child = node.firstChild;
while ( child )
{
next = child.nextSibling;
walk(child);
child = next;
}
break;
case 3: // Text node
handleText(node);
break;
}
}
function handleText(textNode)
{
var v = textNode.nodeValue;
var regexReplace = "Name of troll(.*)"
v = v.replace(new RegExp(regexReplace), '');
textNode.nodeValue = v;
}
this is what the html looks like:
class="up" style="padding-left: 14px" id="pid_31519766" data-pid="31519766"><div class="posting08 ch_wissenschaft"><div class="thread" style="width: 505px" id="t31519766" data-pid="31519766"><div class="row1"><div class="l" style="width:336px "><a class="offset" name="pid31519766"></a><div class="uname" style="max-width:277px "><a rel="nofollow" href="/Userprofil/ByPosting/31519766">NAME OF TROLL</a></div><div class="utools"><a rel="nofollow" class="follow" onclick="STD.FollowingRelationships.followUser(31519766,1363710557719,escape('Orakel von Silesia'))" title="Mitposter von „NAME OF TROLL” werden. „NAME OF TROLL” hat 7 Mitposter.">7</a></div></div><div class="r"><a class="std-button rate p" title="Sehr lesenswert" rel="nofollow" onclick="STD.Forum.rate('31519766',1);">+</a></div><div class="r"><a class="std-button rate n" title="Nicht lesenswert" rel="nofollow" onclick="STD.Forum.rate('31519766', 0);">-</a></div><div class="r rating"><span class="l counter n">14</span><span class="l bar"><span class="wrapper"><span class="n"></span><span class="p"></span></span></span><span class="l counter p">1</span></div><div class="clear"></div></div><div class="row2"><div class="l date" data-timestamp="11.5.2013 15:08:13"><span class="absolute">11.5.2013, 15:08</span><span class="relative"></span></div><div class="r a"><a rel="nofollow" title="Klicken Sie hier, wenn Sie auf dieses Posting antworten möchten." class="onclick" onclick="STD.Forum.post({action: 'reply', id: '31519766', trigger: this}); return false;">antworten</a></div><div class="r p"><a rel="nofollow" title="Mit diesem Link können Sie die URL des Postings aufrufen." href="/plink/1363710557719/31519766">permalink</a></div><div class="r m"><a rel="nofollow" title="Melden Sie Postings an die Redaktion, wenn diese den Community Richtlinien widersprechen." onclick="STD.Forum.report('31519766');">melden</a></div><div class="clear"></div></div></div><div
class="txt" style="width: 505px">
POST I WANNA GET RID OF
</p></div></div></div><div
You could use replace with a regex:
General case (fiddle here):
function escapeRegExp(str) { return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); }
var A = 'AAA'; // string A
var B = 'BBB'; // string B
var testStr = "BEFORE AAA WILL BE REMOVED BBB AFTER CCC BBB again DDD"; // string to be replaced
var stopAtFirstBMatch = testStr.replace(new RegExp(escapeRegExp(A)+'(.*?)'+escapeRegExp(B)), '');
console.assert(stopAtFirstBMatch == "BEFORE AFTER CCC BBB again DDD");
var stopAtLastBMatch = testStr.replace(new RegExp(escapeRegExp(A)+'(.*)'+escapeRegExp(B)), '');
console.assert(stopAtLastBMatch == "BEFORE again DDD");
Your case (fiddle here):
The regex Name(.*?)end of post will match anything starting from 'Name' to the first 'end of post' it finds. ((.*?) is a non-greedy match everything);
In case you mean end of post is the actual end of post, you can use Name(.*) as the regex. It will match every text starting with Name.
var strTest = "Hello my Name is this thal go away until the end of post problem goes away."
var regexEndOfPost = "Name(.*?)end of post"
// alerts: 'Hello my problem goes away'
alert(strTest.replace(new RegExp(regexEndOfPost), ''));
var regexNameToEnd = "Name(.*)" // in case you want from 'Name' to the end of the string
console.log(strTest.replace(new RegExp(regexNameToEnd), ''));
// alerts: 'Hello my '
alert(strTest.replace(new RegExp(regexNameToEnd), ''));

Categories

Resources