avangers Newbie cheater Reputation: 0
Joined: 20 Sep 2017 Posts: 18
|
Posted: Sat Dec 05, 2020 5:44 am Post subject: js source code ( for helping others ) |
|
|
area Of Circle rect sphere triangle
Code: |
function areaOfRectangle(width, height) { return width * height; }
function areaOfSphere(radius) { return 4 * Math.PI * (Math.pow(radius, 2)); }
function areaOfTriangle(baseWidth, height) { return baseWidth * height / 2; }
function areaOfCircle(radius) { return Math.PI * Math.pow(radius, 2); }
|
Decimal to Hex || Hex to Decimal
Code: |
function decToHex(dec) {
var hexStr = "0123456789ABCDEF";
var low = dec % 16;
var high = (dec - low)/16;
var hex = "" + hexStr.charAt(high) + hexStr.charAt(low);
return hex;
}
function hexToDec(hex) { return parseInt(hex,16); }
|
kb to mb || mb to kb
Code: |
function kbToMb(KB) { return KB / 1024; }
function mbToKb(MB) { return MB * 1024; }
|
Celsius to Fahrneite || Fahrneite to Celsius
Code: |
function celsiusToFahrenheit(t) { return (212-32)/100 * t + 32; }
function fahrenheitToCelsius(t) { return 100/(212-32) * (t - 32); }
|
Time conventions
Code: |
function hoursToMinutes(hrs) { return hrs*=60; }
function hoursToSeconds(hrs) { return hrs*=3600; }
function minutesToSeconds(min) { return min*=60; }
function secondsToHours(sec) {
var hrs = Math.floor(sec/3600);
var min = Math.floor((sec%3600)/60);
sec = sec % 60;
if(sec<10) {
sec = "0" + sec;
}
if(min<10) {
min = "0" + min;
}
return hrs + ":" + min + ":" + sec;
}
function secondsToMinutes(sec) {
var min = Math.floor(sec/60);
sec = sec % 60;
if(sec<10) {
sec = "0" + sec;
}
if(min<10) {
min = "0" + min;
}
return min + ":" + sec;
}
|
Dialogs ( alert types )
Code: |
alert(messageStr);
confirm(messageStr);// Example:
// value1 = 3; value2 = 4;
// messageBox("text message %s and %s", value1, value2);
// this message box will display the text "text message 3 and 4"
function messageBox() {
var msg = "",
argNum = 0,
startPos,
endPos;
var args = messageBox.arguments;
var numArgs = args.length;
if (numArgs) {
var theStr = args[argNum++];
if (numArgs === 1 || theStr === "") {
msg = theStr;
} else {
startPos = 0;
endPos = theStr.indexOf("%s", startPos);
if (endPos === -1) {
startPos = theStr.length;
}
while (startPos < theStr.length) {
msg += theStr.substring(startPos, endPos);
if (argNum < numArgs) {
msg += args[argNum++];
}
startPos = endPos + 2;
endPos = theStr.indexOf("%s", startPos);
if (endPos === -1) {
endPos = theStr.length;
}
}
if (!msg) {
msg = args[0];
}
}
}
return(msg);
}
prompt(messageStr, inputFieldDefaultText);
|
images
Code: |
// Example:
// randomImage(randomBannerID, ['0.gif',50,50,'1.gif',25,25,'2.gif',50,25]);
// * Dependencies *
// this function requires the following snippet:
// JavaScript/Randomizers/randomNumber
function randomImage(imgTagID, imgArr)
{
var imgSrc, imgW, imgH, r;
r = randomNumber(imgArr.length / 3);
imgSrc = imgArr[r * 3];
imgW = imgArr[(r * 3)+1];
imgH = imgArr[(r * 3)+2];
document.getElementById(imgTagID).src = imgSrc;
document.getElementById(imgTagID).width = imgW;
document.getElementById(imgTagID).height = imgH;
}
// Example:
// simplePreload( '01.gif', '02.gif' );
function simplePreload() {
var args = simplePreload.arguments;
document.imageArray = new Array(args.length);
for (var i = 0; i < args.length; i++) {
document.imageArray[i] = new Image();
document.imageArray[i].src = args[i];
}
}
/*
* Dependencies *
this function requires the following snippets:
JavaScript/images/switchImage
BODY Example:
<body onLoad="mySlideShow1.play(); mySlideShow2.play();">
<img src="originalImage1.gif" name="slide1">
<img src="originalImage2.gif" name="slide2">
SCRIPT Example:
var mySlideList1 = ['image1.gif', 'image2.gif', 'image3.gif'];
var mySlideShow1 = new SlideShow(mySlideList1, 'slide1', 3000, "mySlideShow1");
var mySlideList2 = ['image4.gif', 'image5.gif', 'image6.gif'];
var mySlideShow2 = new SlideShow(mySlideList2, 'slide2', 1000, "mySlideShow2");
*/
function SlideShow(slideList, image, speed, name) {
this.slideList = slideList;
this.image = image;
this.speed = speed;
this.name = name;
this.current = 0;
this.timer = 0;
}
SlideShow.prototype.play = SlideShow_play;
function SlideShow_play() {
if (this.current++ === this.slideList.length - 1) {
this.current = 0;
}
switchImage(this.image, this.slideList[this.current]);
clearTimeout(this.timer);
this.timer = setTimeout(this.name + '.play()', this.speed);
}
function switchImage(imgName, imgSrc) {
if (document.images) {
if (imgSrc !== "none") {
document.images[imgName].src = imgSrc;
}
}
}
|
randomizers
Code: |
/*
* Dependencies *
this function requires the following snippets:
JavaScript/Randomizers/randomNumber
JavaScript/conversions/base_conversion/decToHex
*/
function randomBgColor() {
var r,g,b;
r = decToHex(randomNumber(256)-1);
g = decToHex(randomNumber(256)-1);
b = decToHex(randomNumber(256)-1);
document.body.style.backgroundColor = "#" + r + g + b;
}
function randomNumber(limit){
return Math.floor(Math.random()*limit);
}
var randomColor = Math.floor(Math.random()*16777215).toString(16);
|
bubble sort
Code: |
function bubbleSort(theArray)
{
var i, j;
for (i = theArray.length - 1; i >= 0; i--)
{
for (j = 0; j <= i; j++)
{
if (theArray[j+1] < theArray[j])
{
var temp = theArray[j];
theArray[j] = theArray[j+1];
theArray[j+1] = temp;
}
}
}
return theArray;
}
|
starter scripts
Code: |
function yourFunction()
{
}
<script type="text/javascript">
<!--
function yourFunction()
{
}
//-->
</script>
<script type="text/javascript">
<!--
//-->
</script>
|
string manipulations
Code: |
function stringToUppercase(inputString)
{
return inputString.toUpperCase();
}
function capitalizeWords(string) {
var tmpStr, tmpChar, preString, postString, stringLen;
tmpStr = string.toLowerCase();
stringLen = tmpStr.length;
if (stringLen > 0) {
for (var i = 0; i < stringLen; i++) {
if (i === 0) {
tmpChar = tmpStr.substring(0, 1).toUpperCase();
postString = tmpStr.substring(1, stringLen);
tmpStr = tmpChar + postString;
} else {
tmpChar = tmpStr.substring(i, i + 1);
if (tmpChar === " " && i < (stringLen - 1)) {
tmpChar = tmpStr.substring(i + 1, i + 2).toUpperCase();
preString = tmpStr.substring(0, i + 1);
postString = tmpStr.substring(i + 2, stringLen);
tmpStr = preString + tmpChar + postString;
}
}
}
}
return tmpStr;
}
function checkForCharacters(inputString, checkString, startingIndex) {
if (!startingIndex) {
startingIndex = 0;
}
return inputString.indexOf(checkString);
}
function howManyWords(inputString) {
return inputString.trim().split(/\s+/).length;
}
function htmlEncodeString (inputString) {
return encodeURI(inputString);
}
function htmlUnencodeString (inputString) {
return decodeURI(inputString);
}
function isNotaNumber (inputString)
{
return isNaN(inputString);
}
function isNumberFloat(inputString)
{
return (!isNaN(parseFloat(inputString))) ? true : false;
}
function isNumberInt(inputString) {
return (!isNaN(parseInt(inputString))) ? true : false;
}
function stringToLowercase(inputString)
{
return inputString.toLowerCase();
}
function maxLength(inputString, inputLength) {
return (inputString.length <= inputLength) ? true : false;
}
function minLength(inputString,inputLength)
{
return (inputString.length >= inputLength) ? true : false;
}
function noNumbers(inputString) {
var searchForNumbers = /\d/;
return (searchForNumbers.test(inputString) === false);
}
function numberToString(inputNumber,base) {
var prefix = '';
if (!base) {
base = 10;
} else if (base === 8) {
prefix = '0';
} else if (base === 16) {
prefix = '0x';
}
return (prefix + inputNumber.toString(base));
}
function onlyNumbers(inputString) {
var searchForNonNumbers = /\D+/;
return (searchForNonNumbers.test(inputString) === false);
}
function removeExtraSpaces(string) {
var returnString = "";
var stringArray = string.split(/\s+/);
for (var i = 0; i < stringArray.length; i++) {
if (stringArray[i] !== "") {
if (i === stringArray.length - 1) {
returnString += stringArray[i];
}
else {
returnString += stringArray[i] + " ";
}
}
}
return returnString;
}
function removeLeadingWhitespace(inputString) {
if (typeof inputString === "string") {
var firstNonWhite = inputString.search(/\S/);
if (firstNonWhite !== -1) {
inputString = inputString.substring(firstNonWhite);
}
}
return inputString;
}
function removeLeadingAndTrailingWhitespace(inputString) {
if (typeof inputString === "string") {
var firstNonWhite = inputString.search(/\S/);
if (firstNonWhite !== -1) {
for (var i=inputString.length-1; i >= 0; i--) {
if (inputString.charAt(i).search(/\S/) !== -1) {
inputString = inputString.substring(firstNonWhite, i+1);
break;
}
}
}
}
return inputString;
}
function removeTrailingWhitespace(inputString) {
if (typeof inputString === "string") {
for (var i=inputString.length-1; i >= 0; i--) {
if (inputString.charAt(i).search(/\S/) !== -1) {
inputString = inputString.substring(0, i+1);
break;
}
}
}
return inputString;
}
function replaceCharacters(conversionString,inChar,outChar)
{
var convertedString = conversionString.split(inChar);
convertedString = convertedString.join(outChar);
return convertedString;
}
function stringLength(inputString)
{
return inputString.length;
}
function stringToFloat (inputString)
{
return parseFloat(inputString);
}
function stringToInteger (inputString)
{
return parseInt(inputString);
}
function wrapString(inputString, wrapLength, delimiter) {
if (!delimiter) {
delimiter = '\n';
}
if (!wrapLength) {
wrapLength = inputString.length;
}
var buildString = '';
for (var i = 0; i < inputString.length; i += wrapLength) {
buildString += inputString.slice(i, i + wrapLength) + delimiter;
}
return buildString.slice(0, (buildString.length - delimiter.length));
}
|
Date Display ( date to time )
Code: |
function getTodaysDate() {
var now = new Date();
var days = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
var months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
var date = ((now.getDate() < 10) ? "0" : "") + now.getDate();
var today = days[now.getDay()] + ", " +
months[now.getMonth()] + " " +
date + ", " +
now.getFullYear();
return (today);
}
|
Determine Viewport Size, Screen Resolution, Mouse Position
Code: |
/* Returns viewport's width */
function getViewportWidth() {
if (window.innerWidth) {
/* Returns Window's width excluding toolbars/scrollbars */
return window.innerWidth;
} else if (document.body && document.body.offsetWidth) {
/* Returns viewable width of document,
including padding, border and scrollbar, but not the margin */
return document.body.offsetWidth;
} else {
return 0;
}
}
/* Returns window's height */
function getViewportHeight() {
if (window.innerHeight) {
/* Returns Window's height excluding toolbars/scrollbars */
return window.innerHeight;
} else if (document.body && document.body.offsetHeight) {
/* Returns viewable height of document,
including padding, border and scrollbar, but not the margin */
return document.body.offsetHeight;
} else {
return 0;
}
}
/* Returns screen's total height & width */
function getScreenResolution() {
return {
height: (screen.height)? screen.height : undefined,
width: (screen.width)? screen.width : undefined
};
}
/* Returns coordinates of the mouse pointer relative to the current window, for the given mouse event.
Example, onclick="coords = getMouseCoordinates(event)" or onmousemove="coords = getMouseCoordinates(event)"
*/
function getMouseCoordinates(event) {
var x = (event.clientX)? event.clientX : undefined;
var y = (event.clientY)? event.clientY : undefined;
return { x: x, y: y };
}
|
Get and Set a Cookie
Code: |
/* Create or update a cookie */
function setCookie(cookieName, cookieValue, expdays) {
var d = new Date();
d.setTime(d.getTime() + (expdays * 24 * 60 * 60 * 1000));
var expires = "; expires=" + d.toUTCString();
document.cookie = cookieName + "=" + cookieValue + expires;
}
/* Get cookie value
undefined is returned if the cookie is not available */
function getCookie(cookieName) {
var name = cookieName + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) === ' ') {
c = c.substring(1);
}
if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length);
}
}
return undefined;
}
/* Delete a cookie */
function deleteCookie(name) {
setCookie(name, "", -1);
}
/* Check if username cookie is already created. If not, ask user for the value and create a cookie. */
function checkCookie() {
var username = getCookie("username");
if (username) {
alert("Welcome: " + username);
} else {
username = prompt("Please enter your user name:", "");
if (username !== "" && username !== null) {
setCookie("username", username, 365);
}
}
}
|
those are the script you might can use thank you for looking to the post inside the documents I gonna add a js file with every single function inside of it because this massive bleu is unread able for me I hope someone tell me how to change it thx in advance avangers
( disclaimer ) txt js etc are not supported so I can't send the file here )
_________________
Welcome everyone who sees this under my post or reply. I want to ask you to check out the little message on the art zone, rate it, and if you wish to contact me on my email to be able to get your advertisement picture or anything else you want to for a low price is added to the post regards avangers |
|