An ‘alert’ on the comments interface

  • Unknown's avatar

    Appreciated Sirs,

    below, I paste a piece of code that I would love to implement in one of my posts comments interface. Using the local storage available from the browsers, and after a tutorial book about html 5 and jquery, I simulated a ‘translators hub’ that went across previous records (in a post, it would be previous comments) and made ‘alerts’ of the sort ‘this other person(s) seems to have written something very similiar to what you are writing down’. My idea was to provide a tool to fine tune/discard my own comment if somebody else had already said it in a better fashion.

    I would highly appreciate any advice on how to achieve this in my/your post/service.

    Thanks very much in advance.

    Sincerely

    Gerardo García Cabrero

    var oEntry;

    // el detonador de la funci??n myFunction / listener for text processing myFunction
    if (document.getElementById(‘entry’).
    addEventListener(‘change’, myFunction , false)){
    // nada
    }

    // inicio de la funci??n que lleva a cabo el proceso
    function myFunction() { // llave de inicio de myFunction
    oEntry = document.getElementById(‘entry’);
    // alert (oEntry.value);

    // la entrada a may??sculas / entry to uppercase
    var str = oEntry.value.toUpperCase() + ‘.’;
    // arreglo palabra por palabra… criterio de separaci??n: espacio en blanco / white splice
    var arr = str.split(‘ ‘);
    // variables de sobra / variables to spare / trial error scoping
    var arr2 = [];
    var arr3 = [];
    var arr4 = [];
    var x;
    var arr4_bis = [];
    var text = ”;
    var text2= ”;
    var text3 = ”;
    var text4 = ”;
    var laVar = ”;
    var indice;
    var i;
    var j;
    var r;

    // procesa la id=’entry’ input (palabra por palabra en may??sculas)
    // en text pone en str la frase eliminando puntuaci??n y otros caracteres / gets rid of characters
    // en arr2 y en text2 pone en num/str las longitudes de cada palabra / get the lenght of each word
    for (i = 0; i < arr.length; i++) {
    for (j = 0; j < arr[i].length; j++) {
    if (arr[i].charCodeAt(j) 122)
    {
    arr[i] = arr[i].replace(String.fromCharCode(arr[i].charCodeAt(j)), ”);
    }
    }
    arr2[i] = arr[i].length;
    arr4[i] = arr[i];
    arr4_bis[i] = arr[i]; // I think this is not used
    text += arr[i] + ‘
    ‘ //
    s initially to see the words in a column (no punctuation, accents, etc.)
    text2 += arr2[i] + ‘

    }


    // en text3 ordena las longitudes de mayor a menor / lengths sorted
    arr3 = arr2.sort(function(a, b){return b-a});
    for (i = 0; i < arr3.length; i++) {
    text3 += arr3[i] + '

    }

    // en text4 pone en str la frase ordenada por palabras de mayor a menor / sorts the words
    for (i = 0; i < arr3.length; i++) {
    for (j = 0; j < arr4.length; j++) {
    if (arr3[i] == arr4[j].length) {
    text4 += arr4[j] + ' ' //+ '
    ‘ / gets rid of the
    arr4[j] = ”;
    }
    }
    }

    // en arr6 separa nuevamente la frase en text4 palabra por palabra; criterio: espacio en blanco
    // separates again the phrase into var text4, spliced by whites
    var arr6 = text4.split(‘ ‘);
    //alert (text4);
    // obtiene los datos en los rows de la table / gets the data from the table
    // suppose there must be a finer query to get only the tasks in the database
    x = $(‘table’).contents().filter(‘tbody’).contents(‘tr’).contents().contents();
    count = $(taskPage).find(‘#tblTasks tbody tr’).length; // number of records
    // alert (count);
    indice = 0;
    j = 0;
    for (r = 0; r < count; r++)
    {
    indice = r*6;
    // task is at index times 6 of query in var x
    // pone en laVar el texto de la task del primer,segundo, etc. rengl??n
    // agrega un punto al final de la frase por si el usuario no lo ha escrito
    // appends a dot at end of phrase… don't know if is fully functional
    laVar = x[indice].textContent.toUpperCase() + '.';
    //alert (laVar);
    rebanada = ''; // variable para las slices / variable for each slice
    //j = 0;
    coincidencias = 0; ; // variable para registrar las coincidencias entre el input y las tasks en la tabla
    for (i = 0; i < laVar.length; i++)
    {
    coincidencias = 0; // variable for coincidence counting (entry / tasks in records)
    rebanada += laVar.charAt(i);
    if (laVar.charCodeAt(i)==46) // si se ha encontrado un punto ('.') en el string
    {
    //alert (rebanada);
    // procesamiento para buscar coincidencias / coincidence search
    for (k = 0; k = 5)
    {
    //
    if (rebanada.search(arr6[k]) != -1)
    {
    //
    coincidencias++;
    if (coincidencias >= 3)
    { // ??+ de tres coincidencias? then mostrar la frase
    alert (‘3+ coincidencias [con: ‘ + arr6[k] + ‘] en: ‘ + rebanada + ‘ (registro ‘ + (r+1) + ‘)’);
    // (3+ coincidences [with WORD __] in + phrase + (record number)
    k = arr6.length + 1; // forcing off out of the array bounds
    //
    coincidencias = 0; // put coincidences back to 0
    }
    }
    }
    }
    // fin del procesamiento para buscar coincidencias / end of coincidences search
    rebanada = ”; // initializes the processing slice
    i += 1; // advances in the task’s chain

    }
    }

    // } // hasta aqu??
    }

    quitaEscucha(); // does it help?
    }

    function quitaEscucha() { // does it help?
    document.getElementById(‘entry’).removeEventListener(‘change’, myFunction, false);
    document.getElementById(‘entry’).addEventListener(‘change’, myFunction , false);
    }

  • Hi there,

    Adding custom code like that to your site is only possible on our Business Plan, and additionally you’d need to create a custom WordPress plugin to add that, as we don’t allow modifying your site’s WordPress files directly.

    Add Code to Your Site

  • Unknown's avatar

    Thanks Kokkieh,

    I am sure that the learning curve you kinkdly mention is worth the effort. I hope doing it in a timely and useful manner.

    Thanks again

  • The topic ‘An ‘alert’ on the comments interface’ is closed to new replies.